# How to have to a filter in activescaffold list

**URL:** <https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803>\
**Category:** Rails\
**Created:** [August 24, 2010, 5:37pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803 "2010-08-24T17:37:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 24, 2010, 5:37pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/1 "2010-08-24T17:37:26Z")

</div>

What i want to do is allow only user created records to appear in the  
list and thus make them only able to edit their own. How would I do  
this?

Many thanks,

jakx12.

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 24, 2010, 9:59pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/2 "2010-08-24T21:59:31Z")

</div>

On 24 August 2010 16:37, Zack N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What i want to do is allow only user created records to appear in the  
> list and thus make them only able to edit their own. How would I do  
> this?

Looking at the docs for ActiveScaffold I think you could use the  
conditions\_for\_collection method. However I would advise against  
using ActiveScaffold for the user part of a website. It is good for  
easy access to the database for development and admin purposes but for  
the ‘real’ website I would recommend coding up what you really want  
rather than trying to push ActiveScaffold to the limit. Others may  
disagree with this.

Colin

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 24, 2010, 10:59pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/3 "2010-08-24T22:59:21Z")

</div>

Colin L. wrote:

> On 24 August 2010 16:37, Zack N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > What i want to do is allow only user created records to appear in the  
> > list and thus make them only able to edit their own. How would I do  
> > this?
> 
> Looking at the docs for ActiveScaffold I think you could use the  
> conditions\_for\_collection method. However I would advise against  
> using ActiveScaffold for the user part of a website. It is good for  
> easy access to the database for development and admin purposes but for  
> the ‘real’ website I would recommend coding up what you really want  
> rather than trying to push ActiveScaffold to the limit. Others may  
> disagree with this.
> 
> Colin

Can I just say, thank you sooo much for answering pretty much all my  
questions, and so fast! It is for the admin side of the site, just there  
are two levels of admin. So from what i can see i will be able to put in  
def conditions\_for\_collection

end  
in the controller and place conditions in there that will change the  
find method into the database to give me all the stuff based on the  
conditions i give it in that action. How do i format the conditions  
though?

Thanks.

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 24, 2010, 11:21pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/4 "2010-08-24T23:21:10Z")

</div>

Colin L. wrote:

> On 24 August 2010 21:59, Zack N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > the ‘real’ website I would recommend coding up what you really want  
> > > ï¿½end  
> > > in the controller and place conditions in there that will change the  
> > > find method into the database to give me all the stuff based on the  
> > > conditions i give it in that action. How do i format the conditions  
> > > though?
> 
> 1. First work out what the conditions are - in detail that is.
> 2. Then work out how to enter them.
> 
> Do you know the answer to 1?
> 
> Colin

Yup, the list will only be allowed have records that have a created\_by  
value that is equal to the logged in users name, which is  
current\_user.name

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 25, 2010, 9:22am UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/5 "2010-08-25T09:22:00Z")

</div>

Bump…

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 24, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/6 "2010-08-24T23:12:08Z")

</div>

On 24 August 2010 21:59, Zack N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > the ‘real’ website I would recommend coding up what you really want  
> > end  
> > in the controller and place conditions in there that will change the  
> > find method into the database to give me all the stuff based on the  
> > conditions i give it in that action. How do i format the conditions  
> > though?

1. First work out what the conditions are - in detail that is.
2. Then work out how to enter them.

Do you know the answer to 1?

Colin

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 25, 2010, 9:35am UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/7 "2010-08-25T09:35:36Z")

</div>

On 24 August 2010 22:21, Zack N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 1. Then work out how to enter them.
> > 
> > Do you know the answer to 1?
> > 
> > Colin
> 
> Yup, the list will only be allowed have records that have a created\_by  
> value that is equal to the logged in users name, which is  
> current\_user.name

Are you sure? If you store the users name in created\_by then if the  
user changes his name you will lose the link. It would be more usual  
to have YourModel belongs\_to user and User has\_many your\_models.  
However if that is what you want:

If you are having difficulty understanding the docs then google is  
often very useful. I did a google search on activescaffold  
conditions\_for\_collection and this example and [1] came out top of the  
list. It seems pretty easy. something like

def conditions\_for\_collection  
“created\_by = #{current\_user.name}”  
end

would seem to be a likely first try.

[1]  
[http://wiki.activescaffold.com/wiki/published/Dynamic+conditions\_for\_collection](http://wiki.activescaffold.com/wiki/published/Dynamic+conditions_for_collection)

By the way I see that you have bumped this while I have been typing.  
There is no point bumping so quickly, one has to sleep you know.

Colin

---

<div class="post-metadata">

**Author:** ![jakx12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jakx12](https://www.ruby-forum.com/u/jakx12)\
**Post date:** [August 25, 2010, 12:31pm UTC](https://www.ruby-forum.com/t/how-to-have-to-a-filter-in-activescaffold-list/193803/8 "2010-08-25T12:31:47Z")

</div>

sorry :s, im just working with a deadline. Its a website for my local  
gym (needs to be done by friday) and so the names will not change. I did  
a google aswell, but I couldnt seem to find that, thanks though!
