与 Formtastic 的多对多关联不适合我
我的用例比 RailsCasts 中显示的用例稍微复杂一些。
我收到未知属性:用户错误。
问题和用户通过另一种模型进行多对多关联。 我已在问题模型中指定了 Accepts_nested_attributes_for 。
我的查看代码:
<% semantic_form_for @issue do |form| %>
<% form.inputs do %>
<%= form.input :description, :input_html => { :rows => 5, :cols => 1, :class => 'autogrow' } %>
<%= form.input :location %>
<%= form.input :issue_type %>
<% end %>
<% form.inputs :for => :user do |user_form| %>
<%= user_form.input :email %>
<% end %>
<% form.buttons do %>
<%= form.commit_button "Submit" %>
<% end %>
<% end %>
我的控制器代码:
def create
@issue = Issue.new(params[:issue])
if @issue.save
flash[:notice] = "Thank you"
else
render :action => 'new'
end
end
有什么想法吗? 谢谢!
My use case is a bit more complicated than the one shown in RailsCasts.
I get an unknown attribute: user error.
Issues and users are related by a many-to-many through another model.
I HAVE specified the accepts_nested_attributes_for in my Issue model.
My view code:
<% semantic_form_for @issue do |form| %>
<% form.inputs do %>
<%= form.input :description, :input_html => { :rows => 5, :cols => 1, :class => 'autogrow' } %>
<%= form.input :location %>
<%= form.input :issue_type %>
<% end %>
<% form.inputs :for => :user do |user_form| %>
<%= user_form.input :email %>
<% end %>
<% form.buttons do %>
<%= form.commit_button "Submit" %>
<% end %>
<% end %>
My Controller code:
def create
@issue = Issue.new(params[:issue])
if @issue.save
flash[:notice] = "Thank you"
else
render :action => 'new'
end
end
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在 user_form 中使用
@user
而不是:user
。Try using
@user
instead of:user
in the user_form.