ruby on rails - Whats right way to create object (in database) from controller? -
ruby on rails - Whats right way to create object (in database) from controller? -
i'm trying that:
user upload file in first controller, in conditions show page user take element file , pass file info controller in params: data#newin data#new:
@elm_file = rails.cache.read(params[:cache_id]) @elm_id = params[:index] @user_name = params[:name] new_elm_id = elm.create_from_file @elm_file, @elm_id, @user_name if new_elm_id != 0 redirect_to :action => '', :id => new_elm_id end homecoming
in model:
new_elm = elm.new homecoming new_elm.id
the problem - nil returned. how can record new element database?
your new
action of controller data
returns nothing, because haven't defined behind return
argument.
the 2 other lines, supposed model, returns nothing, because id
field set persisted records. maybe want persist create()
.
ruby-on-rails
Comments
Post a Comment