Hello all, I haven''t been able to find an answer to this, so I thought the collective intelligence of this group might be able to help me out. Basically, I have something close to a blog engine written. Now, I do realize that this is duplicating work, but my employer wants to do so, despite my arguments. Here''s the issue that I''ve run into. Maybe this is a bug in Rails, maybe it''s how I''m using it. I have a text field in the database that I don''t want to necessarily pull in the index action, since it may be large. I''ve created a preview field in the same table that holds a truncated value of the text field. After googling around and reading a few parts of few Rails books, I''ve come to the solution like this: @posts = @user.posts.find(:all, :select => ''title, preview, created_at'', :conditions => [''draft = ?'', false]) As it reads, I want certain columns of the Posts table, scoping through the current user and I want posts that are not published yet. This works perfectly, but for one problem. The RESTful routes I''ve created in the routes.rb file do not give me proper URLs for the show, edit and delete actions. Routes are defined like this: map.resources :users, :has_many => [:posts, :comments] Is this a bug in Rails or is it me? Thanks in advance for any help --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-02 14:19 UTC
Re: :select in find does not work with RESTful routes
On 2 Jul 2008, at 15:11, Srdjan Pejic wrote:> > Hello all, > > I haven''t been able to find an answer to this, so I thought the > collective intelligence of this group might be able to help me out. > Basically, I have something close to a blog engine written. Now, I do > realize that this is duplicating work, but my employer wants to do so, > despite my arguments. Here''s the issue that I''ve run into. Maybe this > is a bug in Rails, maybe it''s how I''m using it. > > I have a text field in the database that I don''t want to necessarily > pull in the index action, since it may be large. I''ve created a > preview field in the same table that holds a truncated value of the > text field. After googling around and reading a few parts of few Rails > books, I''ve come to the solution like this: > > @posts = @user.posts.find(:all, :select => ''title, preview, > created_at'', :conditions => [''draft = ?'', false])You''re not selecting the id field, so rails doesn''t know the id of the post objects which will really screw things up. Fred> > > As it reads, I want certain columns of the Posts table, scoping > through the current user and I want posts that are not published yet. > This works perfectly, but for one problem. The RESTful routes I''ve > created in the routes.rb file do not give me proper URLs for the show, > edit and delete actions. Routes are defined like this: > > map.resources :users, :has_many => [:posts, :comments] > > Is this a bug in Rails or is it me? > > Thanks in advance for any help > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Fred. That will do it. On Jul 2, 10:19 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Jul 2008, at 15:11, Srdjan Pejic wrote: > > You''re not selecting the id field, so rails doesn''t know the id of the > post objects which will really screw things up. > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---