Sunday, 8 September 2013

Redirecting from new function in a resource controller

Redirecting from new function in a resource controller

I'm new to Ruby on Rails. I've seen that in a resources_controller file in
whenever you call resources#new it lands me to new.html.haml file which
contains a form. When I click on Submit button it redirects to me the the
create function of the above resources_controller.rb file. Can anyone
explain me how? Actually I want to do something like this:
I want to create a new student only if the student with a given roll
number doesn't exist. For that new.html.haml contains a form where there
is only one field for roll number, if the student with that roll number
does not exist then a new haml should be called where there will be
another form where one will enter the student details and only after
submission of this latter form create should be called. And when the
student already exits the form fields should be filled automatically.
I cannot figure out how to do this, because whenever I click the submit
button in the form in new.html.haml it is redirecting me always to create.

No comments:

Post a Comment