Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created April 24, 2013 19:25
Show Gist options
  • Save telagraphic/5454836 to your computer and use it in GitHub Desktop.
Save telagraphic/5454836 to your computer and use it in GitHub Desktop.
<%= form_for @project do |f| %>
<%= f.label :name %>
<br>
<%= f.text_field :name %>
<br>
<%= f.label :description %>
<br>
<%= f.text_field :description%>
<br>
<div>
<h3>Assign to:</h3>
<% User.all.each do |user| %>
<%= check_box_tag "project[user_ids][]", user.id %>
<%= user.email %><br>
<% end %>
</div>
<%= f.submit "Create Project" %>
<% end %>
ActiveModel::MassAssignmentSecurity::Error in ProjectsController#create
Can't mass-assign protected attributes: user_ids
Rails.root: /Users/telagraphic/Documents/programming/rails_projects/projecter
Application Trace | Framework Trace | Full Trace
app/controllers/projects_controller.rb:8:in `new'
app/controllers/projects_controller.rb:8:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"/q4GDkWy68ZL80JuZsxoBAvYsF8BXshxYf+y3BK5/Qs=",
"project"=>{"name"=>"Tim Bob",
"description"=>"",
"user_ids"=>["1",
"2"]},
"commit"=>"Create Project"}
class Project < ActiveRecord::Base
attr_accessible :description, :name
has_many :user_projects
has_many :users, :through => :user_projects
validates :name, :presence => true
end
def create
@project = Project.new(params[:project])
if @project.save
redirect_to current_user
else
render 'new'
end
end
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_secure_password
validates_uniqueness_of :email
has_many :user_projects
has_many :projects, :through => :user_projects
end
class UserProject < ActiveRecord::Base
belongs_to :project
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment