Prezes Łukasz
Prezes Łukasz

Reputation: 968

Render another new form

I have two routes with new action for the same resource: individual_trainings :

new_backend_trainer_ind_training GET    /backend/people/:id/trainers/:trainer_id/individual_trainings/new(.:format)         backend/individual_trainings#new

new_backend_individual_training  GET    /backend/individual_trainings/new(.:format)                                         backend/individual_trainings#new

How to specify what type of new should be rendered? If I use render :new, always redirect to second route. I don't want to use redirect_to, because I cannot handle errors for form. Any idea how to do this (I need render :new in create action). Maybe another new and create action?

Update: I think there is a problem with simple_form in new_backend_trainer_ind_training :

= simple_form_for([:backend, @individual_training]) do |f|

it generates wrong url. Is it right?

Upvotes: 1

Views: 48

Answers (1)

pmichna
pmichna

Reputation: 4888

If you want to do it this way (two routes for the same action) then you can pass path to simple_form:

= simple_form_for(@individual_training, url: new_backend_trainer_ind_training_path) do |f|

However, this is a bad approach to use different routes leading to the same action. If this is a different behavior, then you should create another controller with it's new/create action.

Upvotes: 1

Related Questions