ruby on rails chaining 3 actions from one button -
i have controller new, create, , edit actions, amongst others shown below. right now, have 3 buttons in form, 1 start new project (new), button save (create) , 3rd button edit project after created (edit).
i'd create single button combine execution of 3 actions in sequence : new, create, edit.
is possible?
# /projects/new # /projects/new.json def new @project = project.new respond_to |format| format.html # new.html.erb format.json { render :json => @project } end end # /projects/1/edit def edit @project = project.find(params[:id]) end # post /projects # post /projects.json def create @project = project.new(params[:project]) respond_to |format| if @project.save format.html { redirect_to @project, :notice => 'project created.' } format.json { render :json => @project, :status => :created, :location => @project } else format.html { render :action => "new" } format.json { render :json => @project.errors, :status => :unprocessable_entity } end end end
def create @project = project.new(params[:project]) respond_to |format| if @project.save format.html { redirect_to edit_project_path(@project), :notice => 'project created.' } format.json { render :json => @project, :status => :created, :location => @project } else format.html { render :action => "new" } format.json { render :json => @project.errors, :status => :unprocessable_entity } end end end
ruby-on-rails ruby methods controller method-chaining
No comments:
Post a Comment