In routes.rb:
resources :cars do
resources :reviews
end
resources :motorcycles do
resources :reviews
end
In ReviewsController:
before_filter :find_parent
def show
@review = Review.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @review }
end
end
def edit
@review = Review.find(params[:id])
end
# ...
def find_parent
@parent = nil
if params[:car_id]
@parent = Car.find(params[:car_id])
elsif params[:motorcycle_id]
@parent = Motorcycle.find(params[:motorcycle_id])
end
end
Generating the "show" link for a Review is simply (this works):
= link_to "Show", [@parent, @review]
Similarly I would like to reference a generic edit path for a Review, something like (this does not work):
= link_to "Edit", [@parent, @review], :action => 'edit'
Does anyone know if this is possible or, if not, how this might be accomplished?
link_to 'Edit Review', [:edit, @parent, @review]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With