2010-02-14 6 views
3

J'ai une ressource imbriquée singulier comme ceci:imbriquées form_for ressources singulier

map.resources :bookings, :member => { :rate => :post } do |booking| 
    booking.resource :review 
    end 

me donner ces itinéraires:

new_booking_review GET /bookings/:booking_id/review/new(.:format)  {:controller=>"reviews", :action=>"new"} 
    edit_booking_review GET /bookings/:booking_id/review/edit(.:format)  {:controller=>"reviews", :action=>"edit"} 
     booking_review GET /bookings/:booking_id/review(.:format)   {:controller=>"reviews", :action=>"show"} 
         PUT /bookings/:booking_id/review(.:format)   {:controller=>"reviews", :action=>"update"} 
         DELETE /bookings/:booking_id/review(.:format)   {:controller=>"reviews", :action=>"destroy"} 
         POST /bookings/:booking_id/review(.:format)   {:controller=>"reviews", :action=>"create"} 

J'ai essayé:

<% form_for [@booking, @review] do |f| %> 

Ce qui est retourné cette erreur :

undefined method `booking_reviews_path' for #<ActionView::Base:0x10572b888> 

Avec mes commentaires contrôleur

def new 
    @review = Review.new 
    @booking = Booking.find(params[:booking_id]) 
    end 

Mais cela fonctionne ... si je liste l'URL explicitement ...

<% form_for :review, :url => booking_review_path(@booking) do |f| %> 

Ce n'est pas une grosse affaire ... mais je me demande ce que je fais mal.

Merci

Répondre

8

Je pense que form_for suppose toutes les ressources sont imbriquées pluriel ressources. La fixation form_for serait la bonne chose à faire (et je vous invite à submit a bug), mais dans le temps, vous pouvez truquer:

# in app/helpers/application_helper.rb 
module ApplicationHelper 

    def booking_reviews_path(*args) 
    booking_review_path(*args) 
    end 

end 

Vous ne pouvez pas utiliser alias_method parce que la méthode booking_review_path n » Il existe dans ce module, mais c'est essentiellement la même chose.

+0

Il semble qu'il y ait déjà un bug noté: https://rails.lighthouseapp.com/projects/8994/tickets/3675-form_for-doesnt-work-with-new-singleton-nested-resource –

Questions connexes