ruby on rails - Creat new instance of different model from user input in update action -
ruby on rails - Creat new instance of different model from user input in update action -
i developing app user can assing tags pictures. first time uploads image not have chance assign tags. these tags can changed help of best_in_place gem. phone call update action in pictures controller.
here these tags trough params hash. trying create new instance of tags-model each tag, found in params hash. unfortunately though, dont know, how that. first question, since not link form straight tags-controller.
another question: if created tags, don't want store tags in according coloumn in picture-table, ids of tags created. how need manipulate update action create happen?
currently update action looks so:
def update @model = pictures.find params[:id] respond_do |format| params[:pictures][:tags] |tag| tag = @tags.new <- create new tags here end if @model.update_attributes(params[:pictures]) format.json { respond_with_bip(@model) } format.json { redirect_to action: 'show', status: :created, location: @model } end end
i new ruby on rails might easy question, help appreciated.
ruby-on-rails ruby forms model-view-controller model
Comments
Post a Comment