ActiveRecord::RecordNotFound in UsersController#index
找不到没有ID的UserSessionRails.root:C:/Sites/login_app
应用程序跟踪|框架跟踪|完全跟踪app/controllers/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
索引的中
-
类ApplicationController<ActionController::Base
protect_from_forgery
helper_method:current_user private
def current_user_session
return@current_user_session if defined?(@current_user_session)
@current_uuser_session=用户会话。find
end
def current_user
return@current_user if defined?(@current_user)
@current_user=current_user_session&;current_user_session.record
end
end -
类家庭控制器<ApplicationController
def index
end
end -
类UserSessionsController<ApplicationController
def new
@user_session=UserSession.new
responsd_to do|format|
format.html#new.html.erb
format.xml{render:xml=>@user.session}
end
enddef-create
@user_session=UserSession.new(params[:user_session_])
responsed_to|format|
if@user_session.save
format.html{redirect_to(:users,:notice=>"登录成功"{render:xml=>@user_session.errors,:status=>:unprocessable_entity}
end
end
def destroy
@user-session=UserSession。find
@user_session。destroy
responsd_to do|format|
format.html{redirect_to(:users,:notice=>'再见!')}
format.xml{head:ok}
end
end -
类用户控制器<ApplicationController
def index
@users=User.all
responsd_to do|format|
format.html#index.html.erb
format.json{render json:@users}
end
enddef-show
@user=user.find(params[:id])
responsd_to do|format|
format.html#show.html.erb
format.json{render json:@user}
end
enddef new
@user=user.new
responsd_to do|format|
format.html#new.html.erb
format.json{render json:@user}
end
def edit
@user=user.fund(params[:id])
enddef-create
@user=user.new(params[:user]
end
end
end
def update
@user=user.find(params[:id])
responsd_to do|format|
if@user.update_attributes(params]:user]
end
end
end
def destroy
@user=user.find(params[:id])
@user.dedestroy
responsd_to do|format|
format.html{redirect_to users_url}
form.json{head:no_content}
end
end
-
layout/application.html
LoginApp
<%=stylesheet_link_tag:all%>
<%=javascript_include_tag:默认值%>
<%=csrf_meta_tag%>
<%如果current_user%>
<%=link_to"编辑配置文件",Edit_user_path(current_user.id)%>
<%=link_to"注销",:Logout%>
<%其他%>
<%=link_to"注册",new_user_path%>
<%=link_to"登录",:Login%>
<%end%>
<%=收益率%> -
user_session_form.html
<%=form_for(@user_session)do|f|%>
<%如果@user_session.errors.any?%><%=plularize(@user_session.errors.count,"error")%>禁止保存此用户会话:
- <%=消息%>
<%@user_session.errors.full_messages.each do|msg|%>
<%end%>
<%end%>
<%=f.label:用户名%>
<%=f.text_field:用户名%>
<%=f.label:密码%>
<%=f.password_fields:密码%>
<%=f.提交%>
<%end%> -
user_sessions/edit.html
编辑user_sessions
<%=呈现'form'%>
<%=link_to"显示",@user_session%>
|<%=link_to"返回",user_session_path%>
-
user_sessions/index.html:
列出user_sessions
用户名
密码
<%@user_sessions.each do | user_sessions |%>
<%=user_session.username%>
<%=user_session.password%>
<%=link_to"显示",user_session%>
<%=link_to"编辑",Edit_user_session\upath(用户会话)%>
<%=link_to"销毁",user_session,方法::delete,数据:{confirm:"确定吗?"}%>
<%end%>
<%=link_to"新用户会话",New_User_session_path%>
- user_sessions/new.html
登录
<%=呈现"表单"%>
<%=link_to"返回",user_session_path%>
- user_sessions/show.html
<%=通知%>
用户名:
<%=@user_session.username%>
密码:
<%=@user_session.password%>
<%=link_to"编辑",Edit_user_session\upath(@user_session)%>
|<%=link_to"返回",user_session_path%>
-users/_form.html
<%=form_for(@user)do|f|%>
<%如果@user.errors.any?%>
<%=plularize(@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:用户名%>
<%=f.text_field:用户名%>
<%=f.标签:电子邮件%>
<%=f.text_field:电子邮件%>
<%=f.label:密码%>
<%=f.password_field:密码%>
<%=f.label:密码确认%>
<%=f.password_field:password_confirmation%>
<%=f.提交"创建用户"%>
<%end%>
- users/edit.html
编辑用户
<%=呈现"表单"%>
<%=link_to"显示",@user%>
|<%=link_to"返回",users_path%>
- users/index.html:
列出用户
<%=通知%>
用户名
电子邮件
br/>
<%@users.eachdo|user|%>
<%=user.username%>
<%=user.email%>
<%=link_to"显示",用户%>
<%=link_to"编辑",Edit_user_path(用户)%>
<%=link_to'销毁',user,:confirm=>'你确定吗?',:方法=>:删除%>
<%end%>
<%=link_to"新用户",New_User_path%>
- users/new.html:
新用户
<%=呈现'form'%>
<%=link_to"返回",users_path%>
- users/show.html:
<%=通知%>
用户名:
<%=@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
此外,下次使用要点或类似的东西粘贴大块代码,或者至少格式化它。希望能有所帮助!