Hello! I''m trying to create a list of user "ads" on my home page in my app. But I don''t get it to work. I''m a rails noob so it might be something trivial. I''m currently running into this error: Couldn''t find User without an ID My pages controller where to home action is looks like this: def home @title = "Startsidan" @user = User.find(params[:id]) @ads = @user.Ad.paginate(:page => params[:page]) end And my ad partial looks like this: <div class="ad body_copy"> <%= image_tag user.avatar.url(:thumb) %> <span class="content"> <%= link_to user.name, user %> <%= user.ads.content %> </span> </div> Any help would be appreciated! I hope that my explanation is clear enough. Best regards Anders -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 September 2010 11:34, Anders_P <anders-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote:> Hello! > I''m trying to create a list of user "ads" on my home page in my app. > But I don''t get it to work. I''m a rails noob so it might be something > trivial. > I''m currently running into this error: > > Couldn''t find User without an IDThere should be a lot more information available with the error, including where it has failed. The clue may be in the error message though, it is trying to find a user and there is no id.> > My pages controller where to home action is looks like this: > > def home > @title = "Startsidan" > @user = User.find(params[:id])Possibly this is the problem line, if so then perhaps params[:id] is nil (hence the error message). Have a look in the log (log/development.log) and it will tell you what the params are. Are you passing the id to the home action? Also you could have a look at the rails guide on debugging to see how to break into your application using ruby-debug and examine the data at that point. Colin> @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > end > > And my ad partial looks like this: > > <div class="ad body_copy"> > <%= image_tag user.avatar.url(:thumb) %> > <span class="content"> > <%= link_to user.name, user %> > <%= user.ads.content %> > </span> > </div> > > Any help would be appreciated! I hope that my explanation is clear > enough. > > Best regards > Anders > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Colin! Thanks for your reply. You are right about where the error is occurring, this line is causing the error, @user User.find(params[:id]). I haven''t passed the id to the home action, where should i do that and how? Sorry for the noobish question but your help would be gold! On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > Hello! > > I''m trying to create a list of user "ads" on my home page in my app. > > But I don''t get it to work. I''m a rails noob so it might be something > > trivial. > > I''m currently running into this error: > > > Couldn''t find User without an ID > > There should be a lot more information available with the error, > including where it has failed. The clue may be in the error message > though, it is trying to find a user and there is no id. > > > > > My pages controller where to home action is looks like this: > > > def home > > @title = "Startsidan" > > @user = User.find(params[:id]) > > Possibly this is the problem line, if so then perhaps params[:id] is > nil (hence the error message). Have a look in the log > (log/development.log) and it will tell you what the params are. Are > you passing the id to the home action? Also you could have a look at > the rails guide on debugging to see how to break into your application > using ruby-debug and examine the data at that point. > > Colin > > > > > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > > end > > > And my ad partial looks like this: > > > <div class="ad body_copy"> > > <%= image_tag user.avatar.url(:thumb) %> > > <span class="content"> > > <%= link_to user.name, user %> > > <%= user.ads.content %> > > </span> > > </div> > > > Any help would be appreciated! I hope that my explanation is clear > > enough. > > > Best regards > > Anders > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 September 2010 12:14, Anders_P <anders-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: Could you not top post please, it is easier to follow the thread if comments are inserted into the previous post. Thanks> Hello Colin! > > Thanks for your reply. You are right about where the error is > occurring, this line is causing the error, @user > User.find(params[:id]). > > I haven''t passed the id to the home action, where should i do that and > how? Sorry for the noobish question but your help would be gold!That depends what you are trying to do. If you explain that we may be able to help. If you do not know what the params hash is all about then you need to work through some basic tutorials. See the rails guides at http://guides.rubyonrails.org/ if you are using Rails 3 or http://guides.rubyonrails.org/v2.3.8/ if using version 2.3.x. Start with Getting Started obviously, then work through the others. Colin> > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: >> >> > Hello! >> > I''m trying to create a list of user "ads" on my home page in my app. >> > But I don''t get it to work. I''m a rails noob so it might be something >> > trivial. >> > I''m currently running into this error: >> >> > Couldn''t find User without an ID >> >> There should be a lot more information available with the error, >> including where it has failed. The clue may be in the error message >> though, it is trying to find a user and there is no id. >> >> >> >> > My pages controller where to home action is looks like this: >> >> > def home >> > @title = "Startsidan" >> > @user = User.find(params[:id]) >> >> Possibly this is the problem line, if so then perhaps params[:id] is >> nil (hence the error message). Have a look in the log >> (log/development.log) and it will tell you what the params are. Are >> you passing the id to the home action? Also you could have a look at >> the rails guide on debugging to see how to break into your application >> using ruby-debug and examine the data at that point. >> >> Colin >> >> >> >> > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) >> > end >> >> > And my ad partial looks like this: >> >> > <div class="ad body_copy"> >> > <%= image_tag user.avatar.url(:thumb) %> >> > <span class="content"> >> > <%= link_to user.name, user %> >> > <%= user.ads.content %> >> > </span> >> > </div> >> >> > Any help would be appreciated! I hope that my explanation is clear >> > enough. >> >> > Best regards >> > Anders >> >> > -- >> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
home action seems to be a member restful action and it needs an id to find the record but you are not declaring that route the right way show the routes please On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 September 2010 12:14, Anders_P <anders-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > Could you not top post please, it is easier to follow the thread if > comments are inserted into the previous post. Thanks > > > Hello Colin! > > > > Thanks for your reply. You are right about where the error is > > occurring, this line is causing the error, @user > > User.find(params[:id]). > > > > I haven''t passed the id to the home action, where should i do that and > > how? Sorry for the noobish question but your help would be gold! > > That depends what you are trying to do. If you explain that we may be > able to help. If you do not know what the params hash is all about > then you need to work through some basic tutorials. See the rails > guides at http://guides.rubyonrails.org/ if you are using Rails 3 or > http://guides.rubyonrails.org/v2.3.8/ if using version 2.3.x. Start > with Getting Started obviously, then work through the others. > > Colin > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > >> > >> > Hello! > >> > I''m trying to create a list of user "ads" on my home page in my app. > >> > But I don''t get it to work. I''m a rails noob so it might be something > >> > trivial. > >> > I''m currently running into this error: > >> > >> > Couldn''t find User without an ID > >> > >> There should be a lot more information available with the error, > >> including where it has failed. The clue may be in the error message > >> though, it is trying to find a user and there is no id. > >> > >> > >> > >> > My pages controller where to home action is looks like this: > >> > >> > def home > >> > @title = "Startsidan" > >> > @user = User.find(params[:id]) > >> > >> Possibly this is the problem line, if so then perhaps params[:id] is > >> nil (hence the error message). Have a look in the log > >> (log/development.log) and it will tell you what the params are. Are > >> you passing the id to the home action? Also you could have a look at > >> the rails guide on debugging to see how to break into your application > >> using ruby-debug and examine the data at that point. > >> > >> Colin > >> > >> > >> > >> > @ads = @user.Ad.paginate(:page => params[:page]) > >> > end > >> > >> > And my ad partial looks like this: > >> > >> > <div class="ad body_copy"> > >> > <%= image_tag user.avatar.url(:thumb) %> > >> > <span class="content"> > >> > <%= link_to user.name, user %> > >> > <%= user.ads.content %> > >> > </span> > >> > </div> > >> > >> > Any help would be appreciated! I hope that my explanation is clear > >> > enough. > >> > >> > Best regards > >> > Anders > >> > >> > -- > >> > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > >> > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > >> > For more options, visit this group athttp:// > groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your tips Colin! Hi radhames! Thanks for your help on my previous topic. Here is my routes.rb file: resources :users resources :sessions, :only => [:new, :create, :destroy] resources :ads, :only => [:new, :create, :destroy] match ''/registrera'', :to => ''users#new'' match ''/inloggning'', :to => ''sessions#new'' match ''/utloggning'', :to => ''sessions#destroy'' root :to => ''pages#home'' match ''/kontakt'', :to => ''pages#contact'' match ''/om'', :to => ''pages#about'' Thanks! // Anders On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> home action seems to be a member restful action and it needs an id to find > the record but you are not declaring that route the right way > show the routes please > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > On 11 September 2010 12:14, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > Could you not top post please, it is easier to follow the thread if > > comments are inserted into the previous post. Thanks > > > > Hello Colin! > > > > Thanks for your reply. You are right about where the error is > > > occurring, this line is causing the error, @user > > > User.find(params[:id]). > > > > I haven''t passed the id to the home action, where should i do that and > > > how? Sorry for the noobish question but your help would be gold! > > > That depends what you are trying to do. If you explain that we may be > > able to help. If you do not know what the params hash is all about > > then you need to work through some basic tutorials. See the rails > > guides athttp://guides.rubyonrails.org/if you are using Rails 3 or > >http://guides.rubyonrails.org/v2.3.8/if using version 2.3.x. Start > > with Getting Started obviously, then work through the others. > > > Colin > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > >> > Hello! > > >> > I''m trying to create a list of user "ads" on my home page in my app. > > >> > But I don''t get it to work. I''m a rails noob so it might be something > > >> > trivial. > > >> > I''m currently running into this error: > > > >> > Couldn''t find User without an ID > > > >> There should be a lot more information available with the error, > > >> including where it has failed. The clue may be in the error message > > >> though, it is trying to find a user and there is no id. > > > >> > My pages controller where to home action is looks like this: > > > >> > def home > > >> > @title = "Startsidan" > > >> > @user = User.find(params[:id]) > > > >> Possibly this is the problem line, if so then perhaps params[:id] is > > >> nil (hence the error message). Have a look in the log > > >> (log/development.log) and it will tell you what the params are. Are > > >> you passing the id to the home action? Also you could have a look at > > >> the rails guide on debugging to see how to break into your application > > >> using ruby-debug and examine the data at that point. > > > >> Colin > > > >> > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > > >> > end > > > >> > And my ad partial looks like this: > > > >> > <div class="ad body_copy"> > > >> > <%= image_tag user.avatar.url(:thumb) %> > > >> > <span class="content"> > > >> > <%= link_to user.name, user %> > > >> > <%= user.ads.content %> > > >> > </span> > > >> > </div> > > > >> > Any help would be appreciated! I hope that my explanation is clear > > >> > enough. > > > >> > Best regards > > >> > Anders > > > >> > -- > > >> > You received this message because you are subscribed to the Google > > Groups "Ruby on Rails: Talk" group. > > >> > To post to this group, send email to > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >> > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > >> > For more options, visit this group athttp:// > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ok there is a problem @user = User.find(params[:id]) <================= params[:id] is pulled from the url query string in rails the convention is this /controller/action/id in cases there you need to pull one specific record /controller/action to pull a collection @user = User.find(params[:id]) here you are pulling an specific user but root :to => ''pages#home'' there is no id at the end of your so params[:id] has nothing in it thats why Couldn''t find User without an ID On Sat, Sep 11, 2010 at 2:08 PM, Anders_P <anders-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote:> Thanks for your tips Colin! > > Hi radhames! > > Thanks for your help on my previous topic. > > Here is my routes.rb file: > > resources :users > resources :sessions, :only => [:new, :create, :destroy] > resources :ads, :only => [:new, :create, :destroy] > > match ''/registrera'', :to => ''users#new'' > > match ''/inloggning'', :to => ''sessions#new'' > match ''/utloggning'', :to => ''sessions#destroy'' > > root :to => ''pages#home'' > match ''/kontakt'', :to => ''pages#contact'' > match ''/om'', :to => ''pages#about'' > > Thanks! > > // Anders > > On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > home action seems to be a member restful action and it needs an id to > find > > the record but you are not declaring that route the right way > > show the routes please > > > > > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > On 11 September 2010 12:14, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > > > Could you not top post please, it is easier to follow the thread if > > > comments are inserted into the previous post. Thanks > > > > > > Hello Colin! > > > > > > Thanks for your reply. You are right about where the error is > > > > occurring, this line is causing the error, @user > > > > User.find(params[:id]). > > > > > > I haven''t passed the id to the home action, where should i do that > and > > > > how? Sorry for the noobish question but your help would be gold! > > > > > That depends what you are trying to do. If you explain that we may be > > > able to help. If you do not know what the params hash is all about > > > then you need to work through some basic tutorials. See the rails > > > guides athttp://guides.rubyonrails.org/if you are using Rails 3 or > > >http://guides.rubyonrails.org/v2.3.8/if using version 2.3.x. Start > > > with Getting Started obviously, then work through the others. > > > > > Colin > > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > wrote: > > > > > >> > Hello! > > > >> > I''m trying to create a list of user "ads" on my home page in my > app. > > > >> > But I don''t get it to work. I''m a rails noob so it might be > something > > > >> > trivial. > > > >> > I''m currently running into this error: > > > > > >> > Couldn''t find User without an ID > > > > > >> There should be a lot more information available with the error, > > > >> including where it has failed. The clue may be in the error message > > > >> though, it is trying to find a user and there is no id. > > > > > >> > My pages controller where to home action is looks like this: > > > > > >> > def home > > > >> > @title = "Startsidan" > > > >> > @user = User.find(params[:id]) > > > > > >> Possibly this is the problem line, if so then perhaps params[:id] is > > > >> nil (hence the error message). Have a look in the log > > > >> (log/development.log) and it will tell you what the params are. Are > > > >> you passing the id to the home action? Also you could have a look > at > > > >> the rails guide on debugging to see how to break into your > application > > > >> using ruby-debug and examine the data at that point. > > > > > >> Colin > > > > > >> > @ads = @user.Ad.paginate(:page => params[:page]) > > > >> > end > > > > > >> > And my ad partial looks like this: > > > > > >> > <div class="ad body_copy"> > > > >> > <%= image_tag user.avatar.url(:thumb) %> > > > >> > <span class="content"> > > > >> > <%= link_to user.name, user %> > > > >> > <%= user.ads.content %> > > > >> > </span> > > > >> > </div> > > > > > >> > Any help would be appreciated! I hope that my explanation is clear > > > >> > enough. > > > > > >> > Best regards > > > >> > Anders > > > > > >> > -- > > > >> > You received this message because you are subscribed to the Google > > > Groups "Ruby on Rails: Talk" group. > > > >> > To post to this group, send email to > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > >> > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > >> > For more options, visit this group athttp:// > > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi radhames! So the problem lies in my routes!?!, do you have any suggestion on how it should look? Thanks! // Anders On 12 Sep, 04:48, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ok there is a problem > > @user = User.find(params[:id]) <================= params[:id] is pulled > from the url query string > > in rails the convention is this > > /controller/action/id > > in cases there you need to pull one specific record > > /controller/action > > to pull a collection > > @user = User.find(params[:id]) > > here you are pulling an specific user but > > root :to => ''pages#home'' > > there is no id at the end of your so params[:id] has nothing in it > > thats why Couldn''t find User without an ID > > > > On Sat, Sep 11, 2010 at 2:08 PM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > Thanks for your tips Colin! > > > Hi radhames! > > > Thanks for your help on my previous topic. > > > Here is my routes.rb file: > > > resources :users > > resources :sessions, :only => [:new, :create, :destroy] > > resources :ads, :only => [:new, :create, :destroy] > > > match ''/registrera'', :to => ''users#new'' > > > match ''/inloggning'', :to => ''sessions#new'' > > match ''/utloggning'', :to => ''sessions#destroy'' > > > root :to => ''pages#home'' > > match ''/kontakt'', :to => ''pages#contact'' > > match ''/om'', :to => ''pages#about'' > > > Thanks! > > > // Anders > > > On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > home action seems to be a member restful action and it needs an id to > > find > > > the record but you are not declaring that route the right way > > > show the routes please > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > On 11 September 2010 12:14, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > > > Could you not top post please, it is easier to follow the thread if > > > > comments are inserted into the previous post. Thanks > > > > > > Hello Colin! > > > > > > Thanks for your reply. You are right about where the error is > > > > > occurring, this line is causing the error, @user > > > > > User.find(params[:id]). > > > > > > I haven''t passed the id to the home action, where should i do that > > and > > > > > how? Sorry for the noobish question but your help would be gold! > > > > > That depends what you are trying to do. If you explain that we may be > > > > able to help. If you do not know what the params hash is all about > > > > then you need to work through some basic tutorials. See the rails > > > > guides athttp://guides.rubyonrails.org/ifyou are using Rails 3 or > > > >http://guides.rubyonrails.org/v2.3.8/ifusing version 2.3.x. Start > > > > with Getting Started obviously, then work through the others. > > > > > Colin > > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > > wrote: > > > > > >> > Hello! > > > > >> > I''m trying to create a list of user "ads" on my home page in my > > app. > > > > >> > But I don''t get it to work. I''m a rails noob so it might be > > something > > > > >> > trivial. > > > > >> > I''m currently running into this error: > > > > > >> > Couldn''t find User without an ID > > > > > >> There should be a lot more information available with the error, > > > > >> including where it has failed. The clue may be in the error message > > > > >> though, it is trying to find a user and there is no id. > > > > > >> > My pages controller where to home action is looks like this: > > > > > >> > def home > > > > >> > @title = "Startsidan" > > > > >> > @user = User.find(params[:id]) > > > > > >> Possibly this is the problem line, if so then perhaps params[:id] is > > > > >> nil (hence the error message). Have a look in the log > > > > >> (log/development.log) and it will tell you what the params are. Are > > > > >> you passing the id to the home action? Also you could have a look > > at > > > > >> the rails guide on debugging to see how to break into your > > application > > > > >> using ruby-debug and examine the data at that point. > > > > > >> Colin > > > > > >> > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > > > > >> > end > > > > > >> > And my ad partial looks like this: > > > > > >> > <div class="ad body_copy"> > > > > >> > <%= image_tag user.avatar.url(:thumb) %> > > > > >> > <span class="content"> > > > > >> > <%= link_to user.name, user %> > > > > >> > <%= user.ads.content %> > > > > >> > </span> > > > > >> > </div> > > > > > >> > Any help would be appreciated! I hope that my explanation is clear > > > > >> > enough. > > > > > >> > Best regards > > > > >> > Anders > > > > > >> > -- > > > > >> > You received this message because you are subscribed to the Google > > > > Groups "Ruby on Rails: Talk" group. > > > > >> > To post to this group, send email to > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > >> > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > . > > > > >> > For more options, visit this group athttp:// > > > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Ruby on Rails: Talk" group. > > > > > To post to this group, send email to > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > . > > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
it the route you set a requirement but you could access the client with a query, something like this link_to <http://user.name/>"Home", root_path(:id=>@user.id) but what this does is add this to the url string ?id=1 and is not what you want since people can still access the original with out ?id=1 gicing user the same message so what you do is create a route like this match ''products/:id'' => ''catalog#view'' <============copied from the routes.rb comments you see here the id is specified that means that it the user access product with no id the message will be no routes matched /products and that is what we want, not an error in the controller is just that there is no page in the site you can access without specifing the id. conclusion is not a good idea to have a root route that requieres an id instead match ''pages/:id'' => ''pages#home'' and root :to => "welcome#index" On Sun, Sep 12, 2010 at 7:48 AM, Anders_P <anders-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote:> Hi radhames! > > So the problem lies in my routes!?!, do you have any suggestion on how > it should look? > > Thanks! > > // Anders > > > On 12 Sep, 04:48, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > ok there is a problem > > > > @user = User.find(params[:id]) <================= params[:id] is > pulled > > from the url query string > > > > in rails the convention is this > > > > /controller/action/id > > > > in cases there you need to pull one specific record > > > > /controller/action > > > > to pull a collection > > > > @user = User.find(params[:id]) > > > > here you are pulling an specific user but > > > > root :to => ''pages#home'' > > > > there is no id at the end of your so params[:id] has nothing in it > > > > thats why Couldn''t find User without an ID > > > > > > > > On Sat, Sep 11, 2010 at 2:08 PM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > wrote: > > > Thanks for your tips Colin! > > > > > Hi radhames! > > > > > Thanks for your help on my previous topic. > > > > > Here is my routes.rb file: > > > > > resources :users > > > resources :sessions, :only => [:new, :create, :destroy] > > > resources :ads, :only => [:new, :create, :destroy] > > > > > match ''/registrera'', :to => ''users#new'' > > > > > match ''/inloggning'', :to => ''sessions#new'' > > > match ''/utloggning'', :to => ''sessions#destroy'' > > > > > root :to => ''pages#home'' > > > match ''/kontakt'', :to => ''pages#contact'' > > > match ''/om'', :to => ''pages#about'' > > > > > Thanks! > > > > > // Anders > > > > > On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > home action seems to be a member restful action and it needs an id to > > > find > > > > the record but you are not declaring that route the right way > > > > show the routes please > > > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > > wrote: > > > > > On 11 September 2010 12:14, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > wrote: > > > > > > > Could you not top post please, it is easier to follow the thread if > > > > > comments are inserted into the previous post. Thanks > > > > > > > > Hello Colin! > > > > > > > > Thanks for your reply. You are right about where the error is > > > > > > occurring, this line is causing the error, @user > > > > > > User.find(params[:id]). > > > > > > > > I haven''t passed the id to the home action, where should i do > that > > > and > > > > > > how? Sorry for the noobish question but your help would be gold! > > > > > > > That depends what you are trying to do. If you explain that we may > be > > > > > able to help. If you do not know what the params hash is all about > > > > > then you need to work through some basic tutorials. See the rails > > > > > guides athttp://guides.rubyonrails.org/ifyou are using Rails 3 or > > > > >http://guides.rubyonrails.org/v2.3.8/ifusing version 2.3.x. Start > > > > > with Getting Started obviously, then work through the others. > > > > > > > Colin > > > > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > >> On 11 September 2010 11:34, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > > > wrote: > > > > > > > >> > Hello! > > > > > >> > I''m trying to create a list of user "ads" on my home page in > my > > > app. > > > > > >> > But I don''t get it to work. I''m a rails noob so it might be > > > something > > > > > >> > trivial. > > > > > >> > I''m currently running into this error: > > > > > > > >> > Couldn''t find User without an ID > > > > > > > >> There should be a lot more information available with the error, > > > > > >> including where it has failed. The clue may be in the error > message > > > > > >> though, it is trying to find a user and there is no id. > > > > > > > >> > My pages controller where to home action is looks like this: > > > > > > > >> > def home > > > > > >> > @title = "Startsidan" > > > > > >> > @user = User.find(params[:id]) > > > > > > > >> Possibly this is the problem line, if so then perhaps > params[:id] is > > > > > >> nil (hence the error message). Have a look in the log > > > > > >> (log/development.log) and it will tell you what the params are. > Are > > > > > >> you passing the id to the home action? Also you could have a > look > > > at > > > > > >> the rails guide on debugging to see how to break into your > > > application > > > > > >> using ruby-debug and examine the data at that point. > > > > > > > >> Colin > > > > > > > >> > @ads = @user.Ad.paginate(:page => params[:page]) > > > > > >> > end > > > > > > > >> > And my ad partial looks like this: > > > > > > > >> > <div class="ad body_copy"> > > > > > >> > <%= image_tag user.avatar.url(:thumb) %> > > > > > >> > <span class="content"> > > > > > >> > <%= link_to user.name, user %> > > > > > >> > <%= user.ads.content %> > > > > > >> > </span> > > > > > >> > </div> > > > > > > > >> > Any help would be appreciated! I hope that my explanation is > clear > > > > > >> > enough. > > > > > > > >> > Best regards > > > > > >> > Anders > > > > > > > >> > -- > > > > > >> > You received this message because you are subscribed to the > Google > > > > > Groups "Ruby on Rails: Talk" group. > > > > > >> > To post to this group, send email to > > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > >> > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com> > > > > > . > > > > > >> > For more options, visit this group athttp:// > > > > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > > -- > > > > > > You received this message because you are subscribed to the > Google > > > Groups > > > > > "Ruby on Rails: Talk" group. > > > > > > To post to this group, send email to > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com> > > > > > . > > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Ruby on Rails: Talk" group. > > > > > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > . > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks radhames! I finally got it to work, it turned out that i didn''t need to define @user in my home action, and it was causing the error. Sorry if my description was unclear. Thanks for your help! // Anders On 12 Sep, 20:41, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> it the route you set a requirement but you could access the client with a > query, something like this > > link_to <http://user.name/>"Home", root_path(:id=>@user.id) > > but what this does is add this to the url string > > ?id=1 > > and is not what you want since people can still access the original with > out ?id=1 gicing user the same message > so what you do is create a route like this > > match ''products/:id'' => ''catalog#view'' <============copied from the > routes.rb comments > > you see here the id is specified that means that it the user access product > with no id the message will be > > no routes matched /products > > and that is what we want, not an error in the controller is just that there > is no page in the site you can access without specifing > the id. > > conclusion > is not a good idea to have a root route that requieres an id instead > > match ''pages/:id'' => ''pages#home'' > > and > > root :to => "welcome#index" > > > > On Sun, Sep 12, 2010 at 7:48 AM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > Hi radhames! > > > So the problem lies in my routes!?!, do you have any suggestion on how > > it should look? > > > Thanks! > > > // Anders > > > On 12 Sep, 04:48, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ok there is a problem > > > > @user = User.find(params[:id]) <================= params[:id] is > > pulled > > > from the url query string > > > > in rails the convention is this > > > > /controller/action/id > > > > in cases there you need to pull one specific record > > > > /controller/action > > > > to pull a collection > > > > @user = User.find(params[:id]) > > > > here you are pulling an specific user but > > > > root :to => ''pages#home'' > > > > there is no id at the end of your so params[:id] has nothing in it > > > > thats why Couldn''t find User without an ID > > > > On Sat, Sep 11, 2010 at 2:08 PM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > > wrote: > > > > Thanks for your tips Colin! > > > > > Hi radhames! > > > > > Thanks for your help on my previous topic. > > > > > Here is my routes.rb file: > > > > > resources :users > > > > resources :sessions, :only => [:new, :create, :destroy] > > > > resources :ads, :only => [:new, :create, :destroy] > > > > > match ''/registrera'', :to => ''users#new'' > > > > > match ''/inloggning'', :to => ''sessions#new'' > > > > match ''/utloggning'', :to => ''sessions#destroy'' > > > > > root :to => ''pages#home'' > > > > match ''/kontakt'', :to => ''pages#contact'' > > > > match ''/om'', :to => ''pages#about'' > > > > > Thanks! > > > > > // Anders > > > > > On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > home action seems to be a member restful action and it needs an id to > > > > find > > > > > the record but you are not declaring that route the right way > > > > > show the routes please > > > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...-gM/Ye1E23myhRSP0FMvGiw@public.gmane.orgm> > > > > wrote: > > > > > > On 11 September 2010 12:14, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > > wrote: > > > > > > > Could you not top post please, it is easier to follow the thread if > > > > > > comments are inserted into the previous post. Thanks > > > > > > > > Hello Colin! > > > > > > > > Thanks for your reply. You are right about where the error is > > > > > > > occurring, this line is causing the error, @user > > > > > > > User.find(params[:id]). > > > > > > > > I haven''t passed the id to the home action, where should i do > > that > > > > and > > > > > > > how? Sorry for the noobish question but your help would be gold! > > > > > > > That depends what you are trying to do. If you explain that we may > > be > > > > > > able to help. If you do not know what the params hash is all about > > > > > > then you need to work through some basic tutorials. See the rails > > > > > > guides athttp://guides.rubyonrails.org/ifyouare using Rails 3 or > > > > > >http://guides.rubyonrails.org/v2.3.8/ifusingversion 2.3.x. Start > > > > > > with Getting Started obviously, then work through the others. > > > > > > > Colin > > > > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > >> On 11 September 2010 11:34, Anders_P <and...@andersplanting.se> > > > > wrote: > > > > > > > >> > Hello! > > > > > > >> > I''m trying to create a list of user "ads" on my home page in > > my > > > > app. > > > > > > >> > But I don''t get it to work. I''m a rails noob so it might be > > > > something > > > > > > >> > trivial. > > > > > > >> > I''m currently running into this error: > > > > > > > >> > Couldn''t find User without an ID > > > > > > > >> There should be a lot more information available with the error, > > > > > > >> including where it has failed. The clue may be in the error > > message > > > > > > >> though, it is trying to find a user and there is no id. > > > > > > > >> > My pages controller where to home action is looks like this: > > > > > > > >> > def home > > > > > > >> > @title = "Startsidan" > > > > > > >> > @user = User.find(params[:id]) > > > > > > > >> Possibly this is the problem line, if so then perhaps > > params[:id] is > > > > > > >> nil (hence the error message). Have a look in the log > > > > > > >> (log/development.log) and it will tell you what the params are. > > Are > > > > > > >> you passing the id to the home action? Also you could have a > > look > > > > at > > > > > > >> the rails guide on debugging to see how to break into your > > > > application > > > > > > >> using ruby-debug and examine the data at that point. > > > > > > > >> Colin > > > > > > > >> > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > > > > > > >> > end > > > > > > > >> > And my ad partial looks like this: > > > > > > > >> > <div class="ad body_copy"> > > > > > > >> > <%= image_tag user.avatar.url(:thumb) %> > > > > > > >> > <span class="content"> > > > > > > >> > <%= link_to user.name, user %> > > > > > > >> > <%= user.ads.content %> > > > > > > >> > </span> > > > > > > >> > </div> > > > > > > > >> > Any help would be appreciated! I hope that my explanation is > > clear > > > > > > >> > enough. > > > > > > > >> > Best regards > > > > > > >> > Anders > > > > > > > >> > -- > > > > > > >> > You received this message because you are subscribed to the > > Google > > > > > > Groups "Ruby on Rails: Talk" group. > > > > > > >> > To post to this group, send email to > > > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > >> > To unsubscribe from this group, send email to > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > e@googlegroups.com> > > > > > > . > > > > > > >> > For more options, visit this group athttp:// > > > > > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > > -- > > > > > > > You received this message because you are subscribed to the > > Google > > > > Groups > > > > > > "Ruby on Rails: Talk" group. > > > > > > > To post to this group, send email to > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > > To unsubscribe from this group, send email to > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > e@googlegroups.com> > > > > > > . > > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > -- > > > > > > You received this message because you are subscribed to the Google > > > > Groups > > > > > > "Ruby on Rails: Talk" group. > > > > > > To post to this group, send email to > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > > . > > > > > > To unsubscribe from this group, send email to > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > e@googlegroups.com> > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You might take a look at your routes for future reference. Specifically, take a look at RESTful routing where rails does most of the work for you. The home path you setup could easily be the index path for your base controller. On Sep 12, 4:05 pm, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote:> Thanks radhames! > > I finally got it to work, it turned out that i didn''t need to define > @user in my home action, and it was causing the error. Sorry if my > description was unclear. Thanks for your help! > > // Anders > > On 12 Sep, 20:41, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > it the route you set a requirement but you could access the client with a > > query, something like this > > > link_to <http://user.name/>"Home", root_path(:id=>@user.id) > > > but what this does is add this to the url string > > > ?id=1 > > > and is not what you want since people can still access the original with > > out ?id=1 gicing user the same message > > so what you do is create a route like this > > > match ''products/:id'' => ''catalog#view'' <============copied from the > > routes.rb comments > > > you see here the id is specified that means that it the user access product > > with no id the message will be > > > no routes matched /products > > > and that is what we want, not an error in the controller is just that there > > is no page in the site you can access without specifing > > the id. > > > conclusion > > is not a good idea to have a root route that requieres an id instead > > > match ''pages/:id'' => ''pages#home'' > > > and > > > root :to => "welcome#index" > > > On Sun, Sep 12, 2010 at 7:48 AM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> wrote: > > > Hi radhames! > > > > So the problem lies in my routes!?!, do you have any suggestion on how > > > it should look? > > > > Thanks! > > > > // Anders > > > > On 12 Sep, 04:48, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > ok there is a problem > > > > > @user = User.find(params[:id]) <================= params[:id] is > > > pulled > > > > from the url query string > > > > > in rails the convention is this > > > > > /controller/action/id > > > > > in cases there you need to pull one specific record > > > > > /controller/action > > > > > to pull a collection > > > > > @user = User.find(params[:id]) > > > > > here you are pulling an specific user but > > > > > root :to => ''pages#home'' > > > > > there is no id at the end of your so params[:id] has nothing in it > > > > > thats why Couldn''t find User without an ID > > > > > On Sat, Sep 11, 2010 at 2:08 PM, Anders_P <and...-TlBSdMGKk75YFVMCzM9+FrNAH6kLmebB@public.gmane.org> > > > wrote: > > > > > Thanks for your tips Colin! > > > > > > Hi radhames! > > > > > > Thanks for your help on my previous topic. > > > > > > Here is my routes.rb file: > > > > > > resources :users > > > > > resources :sessions, :only => [:new, :create, :destroy] > > > > > resources :ads, :only => [:new, :create, :destroy] > > > > > > match ''/registrera'', :to => ''users#new'' > > > > > > match ''/inloggning'', :to => ''sessions#new'' > > > > > match ''/utloggning'', :to => ''sessions#destroy'' > > > > > > root :to => ''pages#home'' > > > > > match ''/kontakt'', :to => ''pages#contact'' > > > > > match ''/om'', :to => ''pages#about'' > > > > > > Thanks! > > > > > > // Anders > > > > > > On 11 Sep, 19:21, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > home action seems to be a member restful action and it needs an id to > > > > > find > > > > > > the record but you are not declaring that route the right way > > > > > > show the routes please > > > > > > > On Sat, Sep 11, 2010 at 8:25 AM, Colin Law <clan...@googlemail.com> > > > > > wrote: > > > > > > > On 11 September 2010 12:14, Anders_P <and...@andersplanting.se> > > > wrote: > > > > > > > > Could you not top post please, it is easier to follow the thread if > > > > > > > comments are inserted into the previous post. Thanks > > > > > > > > > Hello Colin! > > > > > > > > > Thanks for your reply. You are right about where the error is > > > > > > > > occurring, this line is causing the error, @user > > > > > > > > User.find(params[:id]). > > > > > > > > > I haven''t passed the id to the home action, where should i do > > > that > > > > > and > > > > > > > > how? Sorry for the noobish question but your help would be gold! > > > > > > > > That depends what you are trying to do. If you explain that we may > > > be > > > > > > > able to help. If you do not know what the params hash is all about > > > > > > > then you need to work through some basic tutorials. See the rails > > > > > > > guides athttp://guides.rubyonrails.org/ifyouareusing Rails 3 or > > > > > > >http://guides.rubyonrails.org/v2.3.8/ifusingversion2.3.x. Start > > > > > > > with Getting Started obviously, then work through the others. > > > > > > > > Colin > > > > > > > > > On 11 Sep, 12:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > >> On 11 September 2010 11:34, Anders_P <and...@andersplanting.se> > > > > > wrote: > > > > > > > > >> > Hello! > > > > > > > >> > I''m trying to create a list of user "ads" on my home page in > > > my > > > > > app. > > > > > > > >> > But I don''t get it to work. I''m a rails noob so it might be > > > > > something > > > > > > > >> > trivial. > > > > > > > >> > I''m currently running into this error: > > > > > > > > >> > Couldn''t find User without an ID > > > > > > > > >> There should be a lot more information available with the error, > > > > > > > >> including where it has failed. The clue may be in the error > > > message > > > > > > > >> though, it is trying to find a user and there is no id. > > > > > > > > >> > My pages controller where to home action is looks like this: > > > > > > > > >> > def home > > > > > > > >> > @title = "Startsidan" > > > > > > > >> > @user = User.find(params[:id]) > > > > > > > > >> Possibly this is the problem line, if so then perhaps > > > params[:id] is > > > > > > > >> nil (hence the error message). Have a look in the log > > > > > > > >> (log/development.log) and it will tell you what the params are. > > > Are > > > > > > > >> you passing the id to the home action? Also you could have a > > > look > > > > > at > > > > > > > >> the rails guide on debugging to see how to break into your > > > > > application > > > > > > > >> using ruby-debug and examine the data at that point. > > > > > > > > >> Colin > > > > > > > > >> > @ads = -FuSKUMRWP+gSM0ZfgEZ7pg@public.gmane.org(:page => params[:page]) > > > > > > > >> > end > > > > > > > > >> > And my ad partial looks like this: > > > > > > > > >> > <div class="ad body_copy"> > > > > > > > >> > <%= image_tag user.avatar.url(:thumb) %> > > > > > > > >> > <span class="content"> > > > > > > > >> > <%= link_to user.name, user %> > > > > > > > >> > <%= user.ads.content %> > > > > > > > >> > </span> > > > > > > > >> > </div> > > > > > > > > >> > Any help would be appreciated! I hope that my explanation is > > > clear > > > > > > > >> > enough. > > > > > > > > >> > Best regards > > > > > > > >> > Anders > > > > > > > > >> > -- > > > > > > > >> > You received this message because you are subscribed to the > > > Google > > > > > > > Groups "Ruby on Rails: Talk" group. > > > > > > > >> > To post to this group, send email to > > > > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > > >> > To unsubscribe from this group, send email to > > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > > e@googlegroups.com> > > > > > > > . > > > > > > > >> > For more options, visit this group athttp:// > > > > > > > groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > > > -- > > > > > > > > You received this message because you are subscribed to the > > > Google > > > > > Groups > > > > > > > "Ruby on Rails: Talk" group. > > > > > > > > To post to this group, send email to > > > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > > > > To unsubscribe from this group, send email to > > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > > e@googlegroups.com> > > > > > > > . > > > > > > > > For more options, visit this group at > > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > > -- > > > > > > > You received this message because you are subscribed to the Google > > > > > Groups > > > > > > > "Ruby on Rails: Talk" group. > > > > > > > To post to this group, send email to > > > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > > > . > > > > > > > To unsubscribe from this group, send email to > > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > > e@googlegroups.com> > > > > > > > . > > > > > > > For more options, visit this group at > > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Ruby on Rails: Talk" group. > > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > > . > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.