2013-10-14 185 views
2

請幫忙!紅寶石Rails4和設計

我是一個紅寶石的初學者在鐵軌上。

我正在更新從簡單的web表單到sqlite3數據庫的值。

問題只是電子郵件&密碼字段被插入到表中。名字,姓氏等顯示值'無'

我使用DEVISE進行身份驗證設置。

這裏是我的user.rb代碼:從我的web表單

<div><%= f.label :first_name %><br /> 
    <%= f.text_field :first_name %></div> 

    <div><%= f.label :last_name %><br /> 
    <%= f.text_field :last_name %></div> 
    <div><%= f.label :profile_name %><br /> 
    <%= f.text_field :profile_name %></div> 

class User < ActiveRecord::Base 

    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

attr_accessible :email, :password, :password_confirmation, :remember_me, 
        :first_name, :last_name, :profile_name 
end 

代碼,並從我的遷移文件夾中的代碼摘錄:

def changed 
    create_table(:users) do |t| 
     t.string :first_name 
     t.string :last_name 
     t.string :profile_name 

t.string :email,    :null => false, :default => "" 
t.string :encrypted_password, :null => false, :default => "" 

請幫助!

回答

0

首先,Devise's Github page實際上有一些關於如何讓它安裝和工作的很好的信息。還有一個RailsCast about Devise

看來你對設計工作非常困惑,我強烈建議你刷新它!


遷移

首先,制定創建其自己的遷移,這將有很多的列內。這是通過設計產生在你的Ruby CMD以下命令:

rails generate devise:install 
rails generate devise MODEL 

一旦你跑了後者的命令,運行:

rake db:migrate 

這將允許您創建數據庫,然後你剛剛創建的意見:

rails generate devise:views 

這在登錄,註冊&其設計用途,以幫助保持驗證你的應用程序運行的其他意見。

+0

感謝您的信息豐富!我知道你引用的命令。但是,是的,我需要看github頁面的設計進行改進。非常感謝!! 祝您好運! 幫我在未來:) – user2878191

0

在rails4中支持強參數,而attr_accessible在Rails4中不推薦使用。 所以添加下面的代碼,並嘗試運行,我希望這會幫助你。

class ApplicationController < ActionController::Base 
    # Prevent CSRF attacks by raising an exception. 
    # For APIs, you may want to use :null_session instead. 

    before_filter :configure_permitted_parameters, if: :devise_controller? 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:firstname, :lastname, :email, :password, :password_confirmation) } 
    end 

    protect_from_forgery with: :exception 
end 
+0

非常感謝艾米特!你救了我的headeache男人!榮譽給你!非常感謝。 – user2878191