Question

I'm trying to create two actions that both go to the "new" view. The only difference is I would like the new_e_drawing action to run the incrament_e method, whereas the new action runs the incrament method.

  def new
    @drawing = Drawing.new
    @drawing = @drawing.incrament(@drawing)

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @drawing }
    end
  end

  def new_e_drawing
    @drawing = Drawing.new
    @drawing = @drawing.incrament_e(@drawing)

    respond_to do |format|
      format.html  new.html.erb
      format.json { render json: @drawing }
    end
  end

I would like both of them to take me to the view named "new". I'm not sure how to set up the routing or the respond_to statement for the new_e_drawing action. I tried these with no success:

 get 'drawings/new' => 'drawings#new_e_drawing'
 match 'drawings/new_e_drawing' => 'drawings#new_e_drawing'

Thanks for the help.

Was it helpful?

Solution

Render the "new" template explicitly in your html block of new_e_drawing action.

 def new
    @drawing = Drawing.new
    @drawing = @drawing.incrament(@drawing)

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @drawing }
    end
  end

  def new_e_drawing
    @drawing = Drawing.new
    @drawing = @drawing.incrament_e(@drawing)

    respond_to do |format|
      format.html { render :template => "new" }
      format.json { render json: @drawing }
    end
  end

In your routes,

match 'drawings/new_e_drawing' => 'drawings#new_e_drawing'

route for new action will be automatically generated by rails since it is part of CRUD

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top