KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having trouble getting a has_many :through association working with Rails 4's strong parameters. I have a model called Checkout and I need to select a person from the Employee model in the new checkout form. Checkouts and Employees are associated through an Employment model. I'm getting this error when I try to create a new checkout: NoMethodError in CheckoutsController#create undefined method `employee' for #<Checkout:0x007ff4f8d07f88> It seems that there's something wrong with either my create action, my checkout parameters or my new checkout form. Here's the create action: def create @user = current_user @checkout = @user.checkouts.build(checkout_params) respond_to do |format| if @checkout.save format.html { redirect_to @checkout, notice: 'Checkout was successfully created.' } else format.html { render action: 'new' } end end end My checkout params: def checkout_params params.require(:checkout).permit(:job, :employee_ids, :shift, :date, :hours, :sales, :tips, :owed, :collected, :notes) end My new checkout form: <div class="field"> <%= f.label :employee %><br> <%= f.collection_select(:employee_ids, Employee.all.collect, :id, :full_name, {:prompt => "Please select"} ) %> </div> But I can't figure out what has changed with Rails 4 and strong parameters. In Rails 3 this type of association and form worked for me using attr_accessible instead of strong_parameters. Relevant Files Full Trace of the error: https://gist.github.com/leemcalilly/0cb9e2b539f9e1925a3d models/checkout.rb: <a href="https://gist.github.com/leemcalilly/012d6eae6b207beb147a
Tags (comma-separated)
Save Edits
Cancel