Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form_for in devise How it works?

rails g devise:views command generated that view

<h2>Sign up</h2>

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

   <div><%= f.label :username %><br />
   <%= f.text_field :username, :autofocus => true %></div>

  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>

  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>

  <div><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></div>

  <div><%= f.submit "Sign up" %></div>
<% end %>

<%= render "devise/shared/links" %>

My question is how does it work " form_for(resource, : as=>resource_name, ..."

like image 271
sonic Avatar asked Oct 20 '25 04:10

sonic


1 Answers

resource is simple a record (or object) - with respect to Devise, it's usually something called User or similar. The rest of the parameters for form_for are options, detailed in the form_for docs.

like image 61
CDub Avatar answered Oct 21 '25 18:10

CDub