# NoMethodError in UsersController#show

**URL:** <https://www.ruby-forum.com/t/nomethoderror-in-userscontroller-show/191463>\
**Category:** Rails\
**Created:** [July 13, 2010, 5:04am UTC](https://www.ruby-forum.com/t/nomethoderror-in-userscontroller-show/191463 "2010-07-13T05:04:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quangn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e47774/32.png) [@quangn](https://www.ruby-forum.com/u/quangn)\
**Post date:** [July 13, 2010, 5:04am UTC](https://www.ruby-forum.com/t/nomethoderror-in-userscontroller-show/191463/1 "2010-07-13T05:04:52Z")

</div>

So I am getting the error

NoMethodError in UsersController#show error  
undefined method `feed’ for nil:NilClass

{“authenticity\_token”=\>“zalkdfsjfksjd;lfs;lfksdkf/2tPzo=”,  
“login”=\>“session”,  
“password”=\>“admin”,  
“commit”=\>“Log in”}

Why is login being set to “session”? Instead of the real login?

This is my form:

 \<% form\_tag session\_path do %\> 

Login \<%= text\_field\_tag 'login' %\>

```
        <p><label class="block" for="password">Password</label>
        <%= password_field_tag 'password' %></p>

        <!-- Comment this if you don't want this functionality -->
        <p><label for="remember_me">Remember me:</label>
        <%= check_box_tag 'remember_me' %></p>

        <p><%= submit_tag 'Log in', :class => "btn", :id =>

```

“login\_btn” %\> \<%= link\_to “Sign Up”, new\_user\_path %\>

  
\<% end %\>  

Here are the relevant controllers and models:  
Users\_Controller:  
def show  
#@user = User.find(params[:id])  
@user = User.find\_by\_login(params[:login])  
#@feed\_items = @user.feed  
@feed\_items = @user.feed  
end

Users Model:  
def feed  
#Post.all(:conditions =\> [“user\_id = ?”, id])  
Post.from\_users\_subscribed\_by(self)  
end

Post Model (using SQLite3) :  
named\_scope :from\_users\_subscribed\_by, lambda { |user|  
subscribed\_by(user) }

private

```
# Return an SQL condition for users followed by the given user.
# We include the user's own id as well.
def self.subscribed_by(user)
  subscribed_ids = %(SELECT subscribed_id FROM subscriptions

```

WHERE subscriber\_id = :user\_id)  
{ :conditions =\> [“user\_id IN (#{subscribed\_ids}) OR user\_id =  
:user\_id”,  
{ :user\_id =\> user }] }  
end

---

<div class="post-metadata">

**Author:** ![quangn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e47774/32.png) [@quangn](https://www.ruby-forum.com/u/quangn)\
**Post date:** [July 13, 2010, 5:34am UTC](https://www.ruby-forum.com/t/nomethoderror-in-userscontroller-show/191463/2 "2010-07-13T05:34:06Z")

</div>

Ok, so I found the issue. The below resource in my routes is the issue.

map.profile\_link ‘/:login’, :controller =\> ‘users’, :action =\> ‘show’

I used this to try and get Twitter-like urls so something like  
[应用宝官网-全网最新最热手机应用游戏下载](http://myapp.com/coolusername).

So what was happening anything after [myapp.com/](http://myapp.com/) was being set at the  
:login so I am not sure how to get the Twitter-like urls plus have  
things like [应用宝官网-全网最新最热手机应用游戏下载](http://myapp.com/posts) or [myapp.com/session](http://myapp.com/session).

Anyone have any clues?
