我在点击主页时遇到以下错误。我花了好几个小时试图弄清楚没有运气。查看调试输出,似乎member_session对象没有获取成员对象类上可用的任何方法。
此页面包含两个表单,一个用于注册,另一个用于登录。
NoMethodError in Members#new
Showing /home/thomas/railsProjects/draughtsWorld/app/views/common/_loginPanel.html.erb where line #23 raised:
Model MemberSession does not respond to nickname
Extracted source (around line #23):
20:
21: <div class="">
22: <%= f.label :nickname, "Nickname" %>
23: <%= f.text_field :nickname, :class => "sign_in_textbox" %>
24: </div>
25:
26: <div class="">
Trace of template inclusion: app/views/members/new.html.erb
Rails.root: /home/thomas/railsProjects/draughtsWorld
Application Trace | Framework Trace | Full Trace
app/views/common/_loginPanel.html.erb:23:in `block in _app_views_common__login_anel_html_erb__835376200_89586240__736259602'
app/views/common/_loginPanel.html.erb:6:in `_app_views_common__login_anel_html_erb__835376200_89586240__736259602'
app/views/members/new.html.erb:7:in `_app_views_members_new_html_erb___591788923_89768980__1034002099'
app/controllers/members_controller.rb:33:in `new'
member.rb
class Member < ActiveRecord::Base
acts_as_authentic
end
member_session.rb
class MemberSession < Authlogic::Session::Base
end
members_controller.rb:
class MembersController < ApplicationController
# GET /members
# GET /members.xml
def index
@members = Member.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @members }
end
end
# GET /members/new
# GET /members/new.xml
def new
@member = Member.new
@member_session = MemberSession.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @member }
end
end
member_sessions_controller.rb:
class MemberSessionsController < ApplicationController
def new
@member_session = MemberSession.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @member_session }
end
end
def create
@member_session = MemberSession.new(params[:member_session])
if @member_session.save
redirect_to root_url
else
format.html { render :action => "new" }
#render :action => :new
end
end
def destroy
@member_session = MemberSession.find
@member_session.destroy
redirect_to root_url
end
end
loginPanel.html.erb
<%= form_for @member_session, :html => { :class => "block" } do |f| %>
<%= debug(@member)%>
<%= debug(@member_session.methods)%>
<h4>Already Signed Up?</h4>
<% if @member_session.errors.any? %>
<ul>
<% @member_session.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<div class="">
<%= f.label :nickname, "Nickname" %>
<%= f.text_field :nickname, :class => "sign_in_textbox" %>
</div>
<div class="">
<%= f.label :password, "Password" %>
<%= f.password_field :password, :class => "sign_in_textbox" %>
</div>
<p class="submit">
<%= f.submit "Login", :class => "submit_button" %>
</p>
<p class="lost_password">
<a href="">Forgot you login details?</a>
</p>
<% end %>
答案 0 :(得分:0)
这是一个答案:
模型MemberSession不响应昵称
会员是否有专栏nickname
?
我认为它应该是username
或login
,所以请尝试将您的视图更改为:
<%= f.label :username, "Nickname" %>
<%= f.text_field :username, :class => "sign_in_textbox" %>
或
<%= f.label :login, "Nickname" %>
<%= f.text_field :login, :class => "sign_in_textbox" %>
编辑: 或者您可以尝试在authlogic配置中指定列名称:
acts_as_authentic do |c|
c.login_field = :nickname
end
它应该完成这项工作。