0
我使用declarative_authorization爲我的應用程序,並有創建新用戶的問題。declarative_authorization問題與創建新用戶
我的用戶模型代碼:
class User < ActiveRecord::Base ROLE_TYPES = ["admin", "user", "guest"] validates_inclusion_of :roles, :in => ROLE_TYPES def role_symbols @role_symbols ||= (roles || []).map{|r| r.to_sym} end
我的視圖代碼:
<% form_for(@user) do |f| %> ... <p> <%= f.label :roles %><br /> <%= f.select :roles, User::ROLE_TYPES, :prompt => "Select a role" %> </p> <%= f.submit 'Add User' %> <% end %>每次我試圖創建一個新用戶,並從下拉列表中選擇角色時
,認爲投訴:
Roles is not included in the list
從腳本/服務器的輸出,我可以看到角色實際上是設置:
"user"=>{"name"=>"kc", "password_confirmation"=>"kc", "roles"=>"guest", "password"=>"kc", "email"=>"[email protected]"}
誰能告訴我什麼是錯?爲什麼驗證不會通過?