I want to be able to write a review for the two models separately (using polymorphic paths with nested associations). At the moment, I have a problem in that if I want to write a review for the city, then the record is created for the country, not for the city
http://localhost:3000/countries/1/reviews/new
good overview is created for the country,
=> #<Review id: 1, content: "", reviewable_id: 1, reviewable_type: "Country", created_at: "2013-03-15 18:57:15", updated_at: "2013-03-15 18:57:15">
but:
http://localhost:3000/countries/1/cities/1/reviews/new
again review created for the country, not for the city
=> [#<Review id: 2, content: "second", reviewable_id: 1, reviewable_type: "Country", created_at: "2013-03-15 19:00:34", updated_at: "2013-03-15 19:00:34">]
Tell me please, how do I get to create a review for the city using using polymorphic paths with nested associations?
my routes.rb:
resources :countries do
resources :reviews
resources :cities do
resources :reviews
end
end
review controller
class ReviewsController < ApplicationController
load_resource :country
load_resource :city
load_and_authorize_resource :review, :through => [:country, :city]
def new; end
def create
respond_to do |format|
if @review.save
format.html { redirect_to @review, notice: 'Review was successfully created.' }
format.json { render json: @review, status: :created, location: @review }
else
format.html { render action: "new" }
format.json { render json: @review.errors, status: :unprocessable_entity }
end
end
end
....
end
reviews index
%h1 Listing reviews
= link_to 'New Review', new_polymorphic_path([@country, @city, :review]) if can? :new, Review
and form
= form_for(@review, url: polymorphic_path([@country, @city, @review])) do |f|
.field
= f.label :content
%br/
= f.text_area :content
.actions
= f.submit
Thanks in advance!