ruby - Creating a nested model by hand in Rails 3 -


i have recipe form has_many ingredients. through (beside point) out of pattern choices, end parameters being passed 'create' action on 'recipes' controller:

{    "commit"   =>"create recipe",    "authenticity_token"   =>"qieydcyoetcmu2bba3bm9x7hsxxtift7cuyuk7yvtpc=",    "utf8"   =>"✓",    "recipe"   =>   {       "title"      =>"",       "url"      =>"",       "site"      =>"",       "instructions"      =>"",       "ingredients_attributes"      =>      {          "0"         =>         {             "quantity"            =>"5",             "name" => "flour"          }       }    } } 

i trying hammer model save @ once, out benefit of form builder. i've tried various ways saved model when call @recipe.save, seems ignored. try making array model expect, , doesn't work either. here controller code i've been messing around with:

  def create     arrayingredients = [];     params[:recipe][:ingredients_attributes].values.each |value|       arrayingredients.push value     end       @recipe = recipe.new(params[:recipe])     @recipe.ingredients.build = arrayingredients           # @ point [{"name"=>"flour"}] , forth     @recipe.user_id = current_user.id     @recipe.title = @recipe.inspect  # debugging purposes     respond_to |format|       if @recipe.save... # stuff 

i feel i'm close on this, missing 1 key thing make saved (currently on terminal window it's showing null in insert statements)

thanks input!

add accepts_nested_attributes_for :ingredients recipe model , (if needed) add attr_accessible :ingredients_attributes


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -