0

Suppose I have three models, Campaign, created by an owner User, and with lots of members (who are users) represented by Membership.

The first Campaign is set with this statement

  belongs_to :user
  has_many :memberships
  has_many :users, :through => :memberships
  accepts_nested_attributes_for :memberships

the second User with this statement

has_many :memberships
has_many :campaigns, :through => :memberships

the third Membership

belongs_to :user
belongs_to :campaign

Now I want to define a nested forms when a campaign is created, allowing the campaign creator to choose among all users, some members of his campaign. So I set

= form_for @campaign do |f|
    = f.text_field :owner, placeholder: "Example Owner", class: "xxlarge"
    - @users.each_value do |value|
        = f.fields_for :memberships do |ff|
            = ff.check_box :user_id

where @users is set in the new method of the Campaign controller as so

@users = User.all

The problem is that I have an error message

Completed 500 Internal Server Error in 113ms

ActionView::Template::Error (Illegal nesting: nesting within plain text is illegal.):
    20:       = f.text_field :owner, placeholder: "Example Owner", class: "xxlarge"
    21: 
    22:   @users.each_value do |value|
    23:     = f.fields_for :memberships do |ff|
    24:         = ff.check_box :user_id

I am quite new to rails and I don't understand where I am going wrong

4

2 回答 2

1

你的意思是-在前面放一个@users.each_value来评估代码吗?

于 2013-06-28T15:06:36.033 回答
0

事实上,我替换@users.each_value@users.each它工作得很好

于 2013-06-28T15:24:20.720 回答