4

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, ..."

4

2 回答 2

3

resource是简单的记录(或对象) - 对于设计,它通常是所谓的User或类似的东西。for 的其余参数form_for是选项,在form_for 文档中有详细说明。

于 2013-11-10T18:28:50.430 回答
0

我注意到 :email 和 :username 都在调用 email_field,这是一个错误。

于 2014-05-15T19:29:06.260 回答