开发者

Can someone point out why these lines of code for authentication don't work?

Not sure what's wrong. I've tried removing the space between the < and开发者_运维百科 % but the app wouldn't run.

< % if logged_in? %>  
  Welcome < %= current_user.username %>! Not you?  
  < %= link_to "Log out", logout_path %>  
< % else %>  
  < %= link_to "Sign up", signup_path %> or  
  < %= link_to "log in", login_path %>.  
< % end %>  

The error I get is:

NoMethodError in Posts#index undefined method `logged_in?' for #<#<Class:0x00000101ab0250>:0x00000101aab0c0> 

Can someone point out why these lines of code for authentication don't work?


Did you mean :

 <% if current_user.logged_in? %> 

Your current piece of code will try to use the logged_in? helper wich i guess is not what you want.


If you are using the "restful_authentication", trying adding include AuthenticatedSystem like below

#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  include AuthenticatedSystem
  .....

logged_in? is a protected method inside the AuthenticatedSystem module

module AuthenticatedSystem
  protected
    # Returns true or false if the <%= file_name %> is logged in.
    # Preloads @current_<%= file_name %> with the <%= file_name %> model if they're logged in.
    def logged_in?
      !!current_<%= file_name %>
    end
    ......

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜