与 Formtastic 的多对多关联不适合我

发布于 2024-10-01 13:05:31 字数 911 浏览 0 评论 0原文

我的用例比 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2024-10-08 13:05:31

尝试在 user_form 中使用 @user 而不是 :user

Try using @user instead of :user in the user_form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文