This works only if one record is matched, but there are two or more records it only prints first of the record. Please help me, i''m just beginner in rails This is my controller: def search @info= Info.find_by_name(params[:desire]) redirect_to :action => ''list2'', :id => @info end And this is my view: <% for column in Info.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <tr> <% for column in Info.content_columns %> <td> <%=h @info.send(column.name) %></td> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Jun 2008, at 12:03, Emre Erisgen wrote:> > This works only if one record is matched, but there are two or more > records it only prints first of the record. Please help me, i''m just > beginner in rails >that''s what find_by_xxx does, it boils down to a find :first. find_all_by_xxx is the find :all equivalent. Fred> This is my controller: > > def search > @info= Info.find_by_name(params[:desire]) > redirect_to :action => ''list2'', :id => @info > end > > And this is my view: > > <% for column in Info.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > <tr> > <% for column in Info.content_columns %> > <td> <%=h @info.send(column.name) %></td> > <% end %> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> that''s what find_by_xxx does, it boils down to a find :first. > find_all_by_xxx is the find :all equivalent. > > Fredi changed the code as >> Info.find_all_by_name(params[:desire]) but this time it gives this error: Routing Error no route found to match "/musteri/list2/#<Info:0x46ada34>/#<Info:0x46ada0c>" with {:method=>:get} -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
because @info now contains several records redirect_to :action => ''list2'', :id => @info so @info is an array like set of ActiveRecords @info.id is only an ruby internal object id redirect_to :action => ''list2'', :id => @info.first should work --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> because @info now contains several records > > redirect_to :action => ''list2'', :id => @info > > so @info is an array like set of ActiveRecords > @info.id is only an ruby internal object id > > redirect_to :action => ''list2'', :id => @info.first > > should workSorry it doesn''t work still it prints the first record. Is there a problem with my view file => list2.rhtml ? I think i must write another for block for loop in array <% for ..............%> ==>>> like this but i really dont know what should i write <% for column in Info.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <tr> <% for column in Info.content_columns %> <td> <%=h @info.send(column.name) %></td> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Jun 2008, at 13:01, Emre Erisgen wrote:> > Thorsten Mueller wrote: >> because @info now contains several records >> >> redirect_to :action => ''list2'', :id => @info >> >> so @info is an array like set of ActiveRecords >> @info.id is only an ruby internal object id >> >> redirect_to :action => ''list2'', :id => @info.first >> >> should work >you''d have to do something like redirect_to url_for(:action => ''list2'') + ''?'' + [1,2,3].to_query(''ids'') Then in your list2 action load the corresponding infos ( params[:ids] will be the list of ids) and iterate over them in your view. Would be easier if you didn''t have the redirect in the middle. Fred> > Sorry it doesn''t work still it prints the first record. Is there a > problem with my view file => list2.rhtml ? > I think i must write another for block for loop in array > <% for ..............%> ==>>> like this but i really dont know what > should i write > > <% for column in Info.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > <tr> > <% for column in Info.content_columns %> > <td> <%=h @info.send(column.name) %></td> > <% end %> > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Please somebody help my problem. Did i ask a difficult or dummy question? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Jun 2008, at 13:16, Emre Erisgen wrote:> > Please somebody help my problem. Did i ask a difficult or dummy > question?You''re being more than a little jumpy if you''re posting this 15 minutes after having posted your question. Fred --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It doesn''t work def search @info= Info.find_all_by_name(params[:desire]) redirect_to url_for(:action => ''list2'') + ''?'' + [1,2,3].to_query(''ids'') end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It doesn''t work def list2 @info = Info.find(params[:ids]) end def search @info= Info.find_all_by_name(params[:desire]) redirect_to url_for(:action => ''list2'') + ''?'' + [1,2,3].to_query(''ids'') end <% for column in Info.content_columns %> <th><%= column.human_name %></th> <% end %> </tr> <tr> <% for column in Info.content_columns %> <td> <%=h @info.send(column.name) %></td> <% end %> Offff. I can''t believe how could be this thing so hard with rails. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Jun 2008, at 13:40, Emre Erisgen wrote:> > It doesn''t work > > def list2 > @info = Info.find(params[:ids]) > end > > def search > @info= Info.find_all_by_name(params[:desire]) > redirect_to url_for(:action => ''list2'') + ''?'' + > [1,2,3].to_query(''ids'') > endThe 1,2,3 was obviously an example. That should be @infos= Info.find_all_by_name(params[:desire]) redirect_to url_for(:action => ''list2'') + ''?'' + @infos.to_query(''ids'')> <% for column in Info.content_columns %> > <th><%= column.human_name %></th> > <% end %> > </tr> > <tr> > <% for column in Info.content_columns %> > <td> <%=h @info.send(column.name) %></td> > <% end %> > > Offff. I can''t believe how could be this thing so hard with rails.Info.find will return an array if you give it an array of ids. You need to iterate over that collection. Any entry level rails tutorial should cover this sort of thing. Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred has (as usual) offered very good help. I believe that your problem is that you have poorly modeled routes. A ''list'' type of action is generally a collection method, not a member method, and thus has no id associated with it. It also makes little sense to respond to one request by fetching the necessary information and _always_ redirecting. Perhaps you should be using: render :action=>''list2'' instead. That way you''d be using the data that you''ve already gathered (@info) and simply rendering it out using the template from another action. Long story short, it''s not Rails that''s the problem, it''s having too loose a grasp on its principles. On Jun 27, 8:16 am, Emre Erisgen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Please somebody help my problem. Did i ask a difficult or dummy > question? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---