私は結婚式の会場にコメントを追加するためのコメントセクションを追加しようとしています。私はこれを行う方法についてチュートリアルをオンラインで続けてきましたが、私は同じポイントに固執し続けています。ruby on rails 4
エラー:
class CommentsController < ApplicationController
def create
@venue = Venue.find(params[:venues_id])
@comment = @venue.comments.create(params[:comment].permit(:name, :body))
redirect_to venue_path(@venue)
end
コメントモデル::
class Comment < ActiveRecord::Base
belongs_to :venues
end
会場モデル:
class Venue < ActiveRecord::Base
#check if user has left venue field blank, if so show error "cannot be blank"
validates :venue, :presence => {:message => "cannot be blank ..."}
#validates :name, presence: true, uniqueness: true
has_many :bookings
has_many :comments
end
ここ
Showing C:/Sites/Innovative_WeddingsLatest/app/views/comments/_form.html.erb where line #1 raised:
unknown attribute 'venue_id' for Comment.
Trace of template inclusion: app/views/venues/show.html.erb
Rails.root: C:/Sites/Innovative_WeddingsLatest
Application Trace | Framework Trace | Full Trace
app/views/comments/_form.html.erb:1:in `_app_views_comments__form_html_erb___721803434_50744988'
app/views/venues/show.html.erb:32:in `_app_views_venues_show_html_erb___40167619_56734404'
は、私が持っているコードです。の
ビュー/コメント/ _form.html.erb
<%= form_for([@venue, @venue.comments.build]) do |f| %>
<p>
<%= f.label :name %>
</p>
<p>
<%= f.label :body %><br>
<%= f.text_area :body %>
</p>
<br>
<p>s
<%= f.submit %>
</p>
<% end %>
ビュー/会場/ show.html.erb
<p id="notice"><%= notice %></p>
<!-- when user clicks on "show" information of the specific venue is displayed on a single page -->
</br>
</br>
</br>
</br>
<p>
<strong>Venue:</strong>
<%= @venue.venue %>
</p>
<p>
<strong>Description:</strong>
<%= @venue.description %>
</p>
<p>
<strong>Price:</strong>
<%= number_to_currency @venue.price, unit: "£" %>
</p>
<p>
<%# if not @venue.img_url.blank? %>
<strong>Img url:</strong>
<%#= image_tag @venue.img_url, :size => "180x250" %>
<%# else %>
<%#= image_tag "no-image.jpg", :size => "180x250" %>
<%# end %>
</p>
<%= render 'comments/form' %>
<%= link_to 'Edit', edit_venue_path(@venue) %> |
<%= link_to 'Back', venues_path %>
コメントの移行:
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :name
t.text :body
t.references :venues
t.timestamps null: false
end
end
end
P.S.申し訳ありませんが、その最初の時は、このフォーラムを使用して、これはもうコードは、問題を解決するために必要とされる場合:(
を最高のを見ていないことが、私に知らせてください:D事前に
感謝:)
schema.dbファイルを表示できますか? – moveson