# Find, using a link instead of a form

**URL:** <https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522>\
**Category:** Rails\
**Created:** [October 19, 2009, 7:13pm UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522 "2009-10-19T19:13:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![snlsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@snlsn](https://www.ruby-forum.com/u/snlsn)\
**Post date:** [October 19, 2009, 7:13pm UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522/1 "2009-10-19T19:13:41Z")

</div>

Hello;  
Here’s the latest puzzle stumping me. Seems it should be simple but  
I’m feeling like a moron. I would like to have a link that, when  
clicked, returns the results of a pre-set find.

Here’s the deal. I’m working on a contact management and scheduling  
app for the photo studio I work for. I want our staff to be able to  
create assignments (think of them as events). Most of the time when an  
assignment is booked, a date and time are established. But sometimes  
the date isn’t certain. Other times we find that an assignment needs  
to be rescheduled but the client doesn’t yet know when.

In either of those cases, the database column “starts\_at” (of type  
datetime) will be empty.

I would like the user interface to have a link (something like  
“Pending Assignments”) which, when clicked, would find and display all  
assignments for which starts\_at is empty. Or starts\_at.year, or  
starts\_at.day or whatever.

I want this to be a link rather than a form input because the find  
criteria is always going to be the same.

I installed the Searchlogic gem but can’t come up with how to get it  
to do what I want.

I have an index action in the assignments\_controller that basically  
does an @assignments = Assignment.find(:all). Can I leverage that so  
that it returns a select set if there is some criteria and all  
Assignments if not? I guess the “some criteria” part is what eludes  
me.

Thanks for any suggestions and pointers.

Steve

---

<div class="post-metadata">

**Author:** ![snlsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@snlsn](https://www.ruby-forum.com/u/snlsn)\
**Post date:** [October 19, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522/2 "2009-10-19T21:56:25Z")

</div>

On Mon, Oct 19, 2009 at 10:12 AM, SNelson [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I would like the user interface to have a link (something like  
> “Pending Assignments”) which, when clicked, would find and display all  
> assignments for which starts\_at is empty. Or starts\_at.year, or  
> starts\_at.day or whatever.

Uh, why not just create an appropriate controller method, something  
like ‘pending’, and use that as the link, e.g. ‘/assignments/pending’ ?

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![snlsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@snlsn](https://www.ruby-forum.com/u/snlsn)\
**Post date:** [October 19, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522/3 "2009-10-19T23:26:34Z")

</div>

Thanks;

> Uh, why not just create an appropriate controller method, something  
> like ‘pending’, and use that as the link, e.g. ‘/assignments/pending’ ?  
> I’ll give that a try. I’m probably over-thinking things - was trying  
> named\_scopes and other new (to me) stuff - but probably basic is  
> better here?  
> Steve

---

<div class="post-metadata">

**Author:** ![snlsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@snlsn](https://www.ruby-forum.com/u/snlsn)\
**Post date:** [October 20, 2009, 12:32am UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522/4 "2009-10-20T00:32:07Z")

</div>

On Mon, Oct 19, 2009 at 1:57 PM, SNelson [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Uh, why not just create an appropriate controller method, something  
> > like ‘pending’, and use that as the link, e.g. ‘/assignments/pending’ ?

> I’ll give that a try. I’m probably over-thinking things - was trying  
> named\_scopes and other new (to me) stuff - but probably basic is  
> better here?

You could use a named\_scope in your model – I would – and then  
combine that with a custom route/controller method to invoke it.

That seems pretty minimalist 🙂

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![snlsn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@snlsn](https://www.ruby-forum.com/u/snlsn)\
**Post date:** [October 20, 2009, 3:02am UTC](https://www.ruby-forum.com/t/find-using-a-link-instead-of-a-form/177522/5 "2009-10-20T03:02:03Z")

</div>

Thanks again.

> That seems pretty minimalist 🙂  
> I like minimalist.  
> Will head in that direction and shout if I fall down any holes along  
> the way.  
> Which is likely.

Steve
