My Rails 애플리케이션에는 두 가지 모델이 있습니다. 위치 및 게시물, 위치는 많은 게시물이 있습니다. 사용하고 있습니다. 가계 보석입니다.게시물 및 위치 조상 보석과의 연관
class Post < ActiveRecord::Base
belongs_to :location, :counter_cache => true
end
class Location < ActiveRecord::Base
include Tree
has_ancestry :cache_depth => true
has_many :posts
end
내 포스트 컨트롤러
나는 위치 _form.html.erb
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved: </h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<%= select :location_id, Location.all.at_depth(4) { |l| [ l.name, l.id ] } %>
<div class="actions">
<%= f.submit %>
</div>
브라우저 쇼 오류에 속해있는 새로운 포스트를 만들 생각하면 전시 인 메시지 울부 짖는 소리
ArgumentError in Posts#new
정확한 오류 메시지를 게시하십시오
는 또한 컨트롤러의
:location_id
매개 변수를 허용 목록에 추가해야합니다. – Pavan** Posts # new ** <% = select : location_id, Location.all.at_depth (4) {| l | [l.name, l.id]} %> –
** 포스트 컨트롤러 **에 문제가 있습니까? _def new_ –