# :select in find does not work with RESTful routes

**URL:** <https://www.ruby-forum.com/t/select-in-find-does-not-work-with-restful-routes/142008>\
**Category:** Rails\
**Created:** [July 2, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/select-in-find-does-not-work-with-restful-routes/142008 "2008-07-02T16:12:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![batasrki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b3f665/32.png) [@batasrki](https://www.ruby-forum.com/u/batasrki)\
**Post date:** [July 2, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/select-in-find-does-not-work-with-restful-routes/142008/1 "2008-07-02T16:12:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![batasrki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b3f665/32.png) [@batasrki](https://www.ruby-forum.com/u/batasrki)\
**Post date:** [July 2, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/select-in-find-does-not-work-with-restful-routes/142008/2 "2008-07-02T16:20:54Z")

</div>

On 2 Jul 2008, at 15:11, Srdjan P. wrote:

> 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

---

<div class="post-metadata">

**Author:** ![batasrki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b3f665/32.png) [@batasrki](https://www.ruby-forum.com/u/batasrki)\
**Post date:** [July 2, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/select-in-find-does-not-work-with-restful-routes/142008/3 "2008-07-02T16:39:58Z")

</div>

Thanks, Fred. That will do it.

On Jul 2, 10:19 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
