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