我正在尝试向full_name我的User模型(使用devisegem)和Rails 4 添加字段/列.
大多数在线示例都建议使用attr_accessible,但听起来在Rails 4中应该采用不同的方式.
我如何添加full_name到我的用户模型?我已经能够成功运行迁移.
文件:迁移> add_full_name_to_users
class AddFullNameToUsers < ActiveRecord::Migration
def change
add_column :users, :full_name, :string
end
end
Run Code Online (Sandbox Code Playgroud)
文件:注册> app/views/devise/registration/new.html
.
.
.
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.label :full_name %>
<%= f.text_field :full_name, :autofocus => true %>
<%= f.label :email %>
<%= f.email_field :email %>
.
.
.
Run Code Online (Sandbox Code Playgroud) 运行rails generate controller Foo home结果:
class FooController < Application Controller
def home
end
end
(There's nothing on this line in the actual file, just a blank line)
Run Code Online (Sandbox Code Playgroud)
这个空白行是否有目的?