Topic: Couldn't find User without an ID

Hi,

I keep getting the following error:

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User without an ID

RAILS_ROOT: /home/meme/rails/avatar
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1509:in `find_from_ids'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:590:in `find'
app/controllers/users_controller.rb:7:in `show'


everything appears fine in my controller and show.html.erb
class UsersController < ApplicationController
  def create
    @user = User.create( params[:user] )
  end
 
  def show
    @user = User.find( params[:id])
  end 
end

#show.html.erb
  <%= image_tag @user.avatar.url %>
  <%= image_tag @user.avatar.url(:medium) %>
  <%= image_tag @user.avatar.url(:thumb) %>


Any help would be appreciated. my pictures show up when I enter:
http://localhost:3000/users/show/1
but not with: http://localhost:3000/users/show

Any help would be appreciated:)

Re: Couldn't find User without an ID

Hi railszav,

Your show method is dependent on the params[:id] with is set when you enter ../show/1 .  In the case where you only call http://localhost:3000/users/show , the @user instance variable is not set and will give the appropriate error.

Hope that helps.

-mdc13

Re: Couldn't find User without an ID

hello,i m new in ruby on rails,i have one problem when i show or edit record it gives eror to me Couldn't find Student without an ID.but when i put http://localhost:3000/student/register/show/1              then it show page but i want that when i click button show i want to get an answer please help me

Last edited by vilas shelke (2012-09-04 02:22:44)

Re: Couldn't find User without an ID

Check ur routes file,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Re: Couldn't find User without an ID

Could you post the page code from which you navigate to the 'show' page (may be 'index' or 'edit') as well as your route.rb file?

Re: Couldn't find User without an ID

For this :- http://localhost:3000/users/show/1
You can modify in routes.rb as  - get "show" => "users/show". It will appear as http://localhost:3000/show.

For the error, I am not getting the exact problem you are facing.
I guess you have to modify your show method as :-
def show
    @user = User.find(params[:id])
    respond_to do |format|
      format.html
    end
  end

& in show.html.erb you should pass current user id.
Hope this helps... smile

Last edited by Avinash (2012-09-04 06:13:23)