Rails How To Write "create" Action In Habtm Model Controller
I'm relatively new to Rails and I am having an enormous difficulty trying to work with models that have HABTM associations between them. These are my models: challenge.rb: class C
Solution 1:
The actual answer is add "skills" to your accepted parameters:
defapproved_params
params.require(:challenge).permit(
:name,
:description,
...
:skills => []
)
end
then have in your create/update:
def update@controller.update(approved_params)
end
That's it
Solution 2:
My advice is to stay away from HABTM and switch to has_many :through
it'll be easier to work with and more flexible to change (add attributes) over time.
See
http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
and
https://stackoverflow.com/a/11601236/631619
and here's a nice comparison of the two:
Post a Comment for "Rails How To Write "create" Action In Habtm Model Controller"