user1107201
user1107201

Reputation: 63

rails form_for submit to "save" or "add another"

I have a representation of a TrainingDrill that has many DrillSteps.

class Drill < ActiveRecord::Base
  has_many :drillsteps
end

class DrillStep < ActiveRecord::Base
  belongs_to :drill
end

When creating a new Drill step I'd like to provide a "save" button and an "add another" button.

The "save" is straight forward and working fine

%= form_for [@drill, @drill_step] do |f| %>
...
<div class="actions">
  <%= f.submit %>
</div>

That routes back nicely to my controller and creates the new drillstep and back to my Drill like I want it to.

Any ideas on how to do an "add another" and get it to call my controller, save drillstep, and then redisplay the New page?

Thanks

Upvotes: 0

Views: 425

Answers (1)

Luis
Luis

Reputation: 545

in yur post activity. Example:

def recieved_params_for_drill
   begin
     @drill = Drill.create(params_for_drill)
     redirect_to  (YOUR ROUTE IN CONTROLLER FOR NEW ACTION)
   rescue => e
     puts e
   end
end

redirect_to (YOUR ROUTE IN CONTROLLER FOR NEW ACTION) => YOUR CHECK IN CONSOLE with rake route command and get a rout for new drill

regards!

Upvotes: 1

Related Questions