正在学习authlogic 这个插件下面是我的学习测试环境 :
rails->2.3.11 monogomapper-> 0.8.6 authlogic-> 2.1.6
新建了一rails学习项目 "authlogic_study"
在项目中:
config/envirmonent.rb 添加了"gem "authlogic"
app/models/auth/user.rb内容如下:
class User
include MongoMapper::Document
key :login, String
key :cryptedpassword, String
key :passwordsalt, String
key :persistencetoken, String
key :singleaccesstoken, String
key :perishabletoken, String
timestamps!
actsasauthentic
end
app/models/auth/user_session.rb"内容如下:
class UserSession < Authlogic::Session::Base
end
config/routes.rb 添加了"
ActionController::Routing::Routes.draw do |map|
map.signin '/signin', :controller => 'auth/user_session', :action => 'new'
map.root :controller => 'welcome'
map.namespace :auth do |auth|
auth.resources :user_session,:collection => {:new=>:any}
end
map.resources :test
end
app/views/auth/user_session/new.html.erb
<% formfor @usersession, :url =>authusersessionindexpath do |form| %>
<%= form.error_messages %>
<%= form.label :login %>
<%= form.text_field :login %>
<%= form.label :password %>
<%= form.password_field :password %>
<%= form.submit 'sing in' %>
<% end %>
到此我的内容差不多了,我是按照网上教程来做的
但是在我进行登录难是时输入表单总是验证失败
Processing Auth::UserSessionController#create (for 127.0.0.1 at 2012-03-06 23:34:27) [POST]
Parameters: {"authenticitytoken"=>"M8Ka41BonO+HNeHi6epRa1UJbJkJTWjydgzF4TQKI6k=", "usersession"=>{"login"=>"admin01", "password"=>"ad"}, "commit"=>"sing in"}
我把传过去的参数输了出来发现:
app/controller/auth/usersession.rb
def create
@usersession = UserSession.new params[:usersession]
puts "==>#{@usersession.login}"
puts "==>#{@user_session.password}"
end
得到结果是:
==>admin01
==>
为什么 这里的"@user_session.password"没有数值呢?
我参考的地址是:http://yuan.iteye.com/blog/646444