正在学习 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 :crypted_password, String key :password_salt, String key :persistence_token, String key :single_access_token, String key :perishable_token, String timestamps! acts_as_authentic 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
<% form_for @user_session, :url =>auth_user_session_index_path 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: {"authenticity_token"=>"M8Ka41BonO+HNeHi6epRa1UJbJkJTWjydgzF4TQKI6k=", "user_session"=>{"login"=>"admin01", "password"=>"ad"}, "commit"=>"sing in"}
我把传过去的参数输了出来发现:
app/controller/auth/user_session.rb
def create
@user_session = UserSession.new params[:user_session]
# puts "==>#{params[:user_session] }"
puts "==>#{@user_session.login}"
puts "==>#{@user_session.password}"
end
得到结果是:
==>admin01
==>
为什么 这里的"@user_session.password"没有数值呢?