我有兩張桌子:場地和評論,其中1個場地可以有很多評論,評論屬於場地。我現在在會場展示頁面的鏈接添加評論到場館的評論新的一頁:如何將新記錄表格移動到相關記錄顯示頁面?
場地/ show.html.erb
<div class="button">
<%= link_to 'Add a review', new_venue_review_path(@venue) %>
</div>
評論/ new.html.erb
<% form_for [@venue, @review] do |f| %>
<p>title: <br>
<%= f.text_field :title %></p>
<%= submit_tag %>
<% end %>
評論控制器
def new
@review = Review.new
end
def create
@review = Review.new params[:review]
@review.venue = @venue
if @review.save
flash[:notice] = 'Review added'
redirect_to venue_path(@venue)
else
render :action => :new
end
end
個
場館控制器
class VenuesController < ApplicationController
def index
if
@venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas])
else
@venues = Venue.all
end
end
def new
@venue = Venue.new
end
def create
@venue = Venue.new params[:venue]
if @venue.save
flash[:notice] = 'Venue added'
redirect_to venues_path
else
render :action => :new
end
end
def edit
@venue = Venue.find(params[:id])
end
def update
@venue = Venue.find(params[:id])
@venue.attributes = params[:venue]
if @venue.save!
flash[:notice] = 'Venue updated successfully'
redirect_to venues_path(@venue)
end
end
def show
@venue = Venue.find(params[:id])
end
end
路線
resources :venues do
resources :reviews
end
end
我如何可以移動增加新的形式審查直接進入場館展示頁面?移動代碼給NilClass:Class錯誤提供了未定義的方法`model_name'。
感謝您的幫助!
什麼場地控制器是什麼樣子? – 2011-03-10 23:11:17
顯示您的場地控制器代碼太 – 2011-03-10 23:11:47
@Ben李和@保羅施雷伯補充說,感謝在看看。 – Dave 2011-03-10 23:15:39