ruby - Rails passing parameters between controller methods -



ruby - Rails passing parameters between controller methods -

so have 2 pages : welcome & details.

in welcome page, i'm asking user input name , click on button takes details page. creates entry in db given name.

in details page, i'm asking age , gender. these details i'm updating in db against name entered in previous page.

now, these 2 methods.

def welcome @name = params[:name] if @fname @record= names.create({:name => @name}) end end def details @human=names.last @human.update_attributes({:age=> params[:age], :gender=> params[:gender]}) end

now, in above code, instead of using names.last, want utilize names.find_by_id(name_id). how pass name_id value between these methods?

the easier way this, without relying on nested form set id of new record in params of detail request. when user clicks on details need go details of record.

so route can include id if want names/:id/details.

your controller

def new names.create(params) end def edit @human = names.find(params[:id]) #whatever else end

without ajax pretty limited here. can't produce entire view code if have 2 views 1 creates new record , edits details, on right track.

a more mutual pattern here new/edit instead of new/details.

so in routes file resources :names. create 7 restful routes. read here, http://guides.rubyonrails.org/routing.html#singular-resources.

for first day of rails have basics down, , next pattern help lot.

ruby-on-rails ruby

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -