0

我有问题在教程用户 sqllite 中关注http://ruby.railstutorial.org/但我是用户 mongoid 有人请帮我说我的英语不好

助手/session_helper.rb

module SessionsHelper

def sign_in(user)
  cookies.permanent[:remember_token] = user.remember_token
  self.current_user = user
end

def signed_in?
  !current_user.nil?
end

def current_user=(user)
  @current_user = user
end


def current_user
  @current_user ||= User.find_by_remember_token(cookies[:remember_token])
end

end

布局/_footer.html.erb

     <header class="navbar navbar-fixed-top navbar-inverse">
     <div class="navbar-inner">
     <div class="container">
     <%= link_to "sample app", root_path, id: "logo" %>
     <nav>
     <ul class="nav pull-right">
      <li><%= link_to "Home", root_path %></li>
      <li><%= link_to "Help", help_path %></li>

      <% if signed_in? %>
        <li><%= link_to "Users", '#' %></li>
        <li id="fat-menu" class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            Account <b class="caret"></b>
          </a>
          <ul class="dropdown-menu">
            <li><%= link_to "Profile", current_user %></li>
            <li><%= link_to "Settings", '#' %></li>
            <li class="divider"></li>
            <li>
              <%= link_to "Sign out", signout_path, method: "delete" %>
            </li>
          </ul>
        </li>
      <% else %>
        <li><%= link_to "Sign in", signin_path %></li>
      <% end %>


     </ul>
      </nav>
      </div>
     </div>
      </header>

对用户有未定义的方法“find_by_remember_token”:我使用 mongoid

4

1 回答 1

0

改变

User.find_by_remember_token(cookies[:remember_token])

User.where(remember_token: cookies[:remember_token]).first rescue nil

问题是 Mongoid 没有创建 Active Record 创建的查找器方法。如果这不能解决问题,您可以发布您的用户模型吗?

于 2013-11-08T15:36:46.283 回答