Question

I am looking at this simple_form_for form (sign up form) (registrations/new.html.erb)

going to users/signup

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

I have looked through the simple_form gem doc on github and checked out the wikis. I have also search for what is a resource on stackoverflow ? I think my question is more like how is simple_form_for using resource? I understand the rest of the code just not this line. I think this form is posting to the registration_path. I do not have a registration_path but I have a

user_registration mapping to the registrations#create method

and my registrations controller inherits from devise registration.

in my routes I have this

devise_for :users, :controllers => {:registrations => "registrations"}
Was it helpful?

Solution

resource is not simple_form specific but devise specific. It is a method defined in DeviseController which gets the actual resource stored in the instance variable of Devise model i.e., User model in your case.

Refer to DeviseController class code in GitHub to checkout the resource method.

As you are customizing the Devise::RegistrationsController, when you submit the form create action of your custom RegistrationsController would be called. If you have not overridden the create action in your custom controller then the call would propagate to the parent class I.e., Devise::RegistrationsController#create

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