ruby on rails - Simple Form HABTM multiple associations on same form -
i using simple_form/rails 4 , want create multiple relationships on same form. models are:
class characteristic < activerecord::base has_and_belongs_to_many :recipes end and
class recipe < activerecord::base has_and_belongs_to_many :characteristics end i have join table
create_table "characteristics_recipes", force: true |t| t.integer "recipe_id" t.integer "characteristic_id" end my form looks like
<%= simple_form_for(@recipe, html: {class: 'form-horizontal' }) |f| %> <div class="form-group"> <%= f.association :characteristics, :as => :collection_select, collection: characteristic.where(category: "prep time"), prompt: "choose prep time", label: "prep time", value_method: :id %> </div> <div class="form-group"> <%= f.association :characteristics, :as => :collection_select, collection: characteristic.where(category: "cook time"), prompt: "choose cook time", label: "cook time", value_method: :id %> </div> <%= f.button :submit %> <% end %> my params capturing second association , string not int ...
{"utf8"=>"✓", "authenticity_token"=>"gr2mvo1s7=", "recipe"=>{ "characteristic_ids"=>"7"}, "commit"=>"create recipe", "action"=>"create", "controller"=>"recipes"} in controller have following permitted params:
def recipe_params params.require(:recipe).permit(:characteristic_ids) end i have tried changing did not matter since not capturing first association
def recipe_params params.require(:recipe).permit(:characteristic_ids => []) end how can multiple associations work here?
thank you!!!!
Comments
Post a Comment