在rails 3上找不到没有ID的UserSession
UsersController#index中的ActiveRecord :: RecordNotFound
如果没有ID Rails.root:C:/ Sites / login_app,找不到UserSession
应用程序跟踪| 框架跟踪| 完整跟踪应用/控制器/ application_controller.rb:9:在current_user_session' app/controllers/application_controller.rb:14:in
current_user'app / views / layouts / application.html.erb:12:在_app_views_layouts_application_html_erb__233847886_33215772' app/controllers/users_controller.rb:7:in
索引'
class ApplicationController <ActionController :: Base
protect_from_forgery
helper_method:current_user私有
def current_user_session
如果已定义,则返回@current_user_session?(@ current_user_session)
@current_user_session = UserSession.find
结束
def current_user
如果已定义,则返回@current_user?(@ current_user)
@current_user = current_user_session && current_user_session.record
结束
结束
类HomeController <ApplicationController
def指数
结束
结束
class UserSessionsController <ApplicationController
def new
@user_session = UserSession.new
respond_to do | format |
format.html#new.html.erb
format.xml {render:xml => @user_session}
结束
结束
def创建
@user_session = UserSession.new(params [:user_session])
respond_to do | format |
如果@ user_session.save
format.html {redirect_to(:users,:notice =>'登录成功')}
format.xml {render:xml => @user_session,:status =>:created,:location => @user_session}
其他
format.html {render:action =>“new”}
format.xml {render:xml => @ user_session.errors,:status =>:unprocessable_entity}
结束
结束
结束
def毁坏
@user_session = UserSession.find
@ user_session.destroy
respond_to do | format |
format.html {redirect_to(:users,:notice =>'Goodbye!')}
format.xml {head:ok}
结束
结束
结束
class UsersController <ApplicationController
def指数
@users = User.all
respond_to do | format |
format.html#index.html.erb
format.json {render json:@users}
结束
结束
def show
@user = User.find(params [:id])
respond_to do | format |
format.html#show.html.erb
format.json {render json:@user}
结束
结束
def new
@user = User.new
respond_to do | format |
format.html#new.html.erb
format.json {render json:@user}
结束
结束
def编辑
@user = User.find(params [:id])
结束
def创建
@user = User.new(params [:user])
respond_to do | format |
如果@ user.save
format.html {redirect_to(:users,:notice =>'注册成功')}
format.xml {render:xml => @user,:status =>:created,:location => @user}
其他
format.html {render:action =>“new”}
format.xml {render:xml => @ user.errors,:status =>:unprocessable_entity}
结束
结束
结束
def更新
@user = User.find(params [:id])
respond_to do | format |
如果@ user.update_attributes(params [:user])
format.html {redirect_to @user,注意:'用户已成功更新。' }
format.json {head:no_content}
其他
format.html {render action:“edit”}
format.json {render json:@ user.errors,status::unprocessable_entity}
结束
结束
结束
def毁坏
@user = User.find(params [:id])
@ user.destroy
respond_to do | format |
format.html {redirect_to users_url}
format.json {head:no_content}
结束
结束
结束
布局/ apllication.html
LoginApp
<%= stylesheet_link_tag:all%>
<%= javascript_include_tag:defaults%>
<%= csrf_meta_tag%>
<%if current_user%>
<%= link_to“编辑配置文件”,edit_user_path(current_user.id)%>
<%= link_to“注销”,:注销%>
<%else%>
<%= link_to“注册”,new_user_path%>
<%= link_to“登录”,:登录%>
<%end%>
<%= yield%>
user_seesion / _form.html
<%= form_for(@user_session)do | f | %>
<%if user_session.errors.any? %>
<%= pluralize(@ user_session.errors.count,“error”)%>禁止保存此user_session:
<%@ user_session.errors.full_messages.each do | msg | %>
<%end%>
<%end%>
<%= f.label:username%>
<%= f.text_field:username%>
<%= f.label:password%>
<%= f.password_fields:password%>
<%= f.submit%>
<%end%>
user_sessions / edit.html
编辑user_session
<%=呈现'表格'%>
<%= link_to'显示',@user_session%>
| <%= link_to'返回',user_sessions_path%>
user_sessions / index.html:
列出user_sessions
用户名
密码
<%@ user_sessions.each do | user_session | %>
<%= user_session.username%>
<%= user_session.password%>
<%= link_to'显示',user_session%>
<%= link_to'编辑',edit_user_session_path(user_session)%>
<%= link_to'Destroy',user_session,method :: delete,data:{confirm:'你确定吗?' }%>
<%end%>
<%= link_to'新用户会话',new_user_session_path%>
登录
<%=呈现'表格'%>
<%= link_to'返回',user_sessions_path%>
<%= notice%>
用户名:
<%= @ user_session.username%>
密码:
<%= @ user_session.password%>
<%= link_to'编辑',edit_user_session_path(@user_session)%>
| <%= link_to'返回',user_sessions_path%>
-Users / _form.html
<%= form_for(@user)do | f | %>
<%if @ user.errors.any? %>
<%= pluralize(@ user.errors.count,“error”)%>禁止该用户保存:
<ul><br/>
<% @user.errors.full_messages.each do |msg| %><br/>
<li><%= msg %></li><br/>
<% end %><br/>
</ul><br/>
</div><br/>
<%end%>
<%= f.label:username%>
<%= f.text_field:username%>
<%= f.label:email%>
<%= f.text_field:email%>
<%= f.label:password%>
<%= f.password_field:password%>
<%= f.label:password_confirmation%>
<%= f.password_field:password_confirmation%>
<%= f.submit'创建用户'%>
<%end%>
编辑用户
<%=呈现'表格'%>
<%= link_to'显示',@user%>
| <%= link_to'返回',users_path%>
列出用户
<%= notice%>
用户名
电子邮件
<%@ users.each do | user | %>
<%= user.username%>
<%= user.email%>
<%= link_to'显示',用户%>
<%= link_to'编辑',edit_user_path(用户)%>
<%= link_to'Destroy',user,:confirm =>'Are you sure?',:method =>:delete%>
<%end%>
<%= link_to'新用户',new_user_path%>
新用户
<%=呈现'表格'%>
<%= link_to'返回',users_path%>
<%= notice%>
用户名:
<%= @ user.username%>
电子邮件:
<%= @ user.email%>
密码密码:
<%= @ user.crypted_password%>
密码盐:
<%= @ user.password_salt%>
持久性标记:
<%= @ user.persistence_token%>
<%= link_to'编辑',edit_user_path(@user)%>
| <%= link_to'返回',users_path%>
在user_session.rb中,您需要将继承的类更改为Authlogic :: Session :: Base,如下所示:
class UserSession < Authlogic::Session::Base
...
end
另外,下次使用要点或类似的东西来粘贴大块代码,或至少格式化它。 希望有所帮助!
链接地址: http://www.djcxy.com/p/35957.html上一篇: Couldn't find UserSession without an ID in ruby on rails 3