Redirecting front to show page for most recently updated project

6 views
Skip to first unread message

Trond Lossius

unread,
Nov 11, 2013, 4:59:33 AM11/11/13
to hobo...@googlegroups.com
Hi,

I have a Hobo app with a Projects model, containing among others a :updated_at field. Now I'd like to redirect the front page of the app to the Show page for the most recently updated project. I've tried several different approaches fiddling around with Routes.rb and projects_controller.rb, but so far to no avail. I guess that I'll need to make a route to something like /projects/latest, and redirect front to this, but I don't manage to find a way of doing so.

Any suggestions for how to solve this would be highly appreciated!

Thanks,
Trond

Ignacio Huerta

unread,
Nov 11, 2013, 1:41:12 PM11/11/13
to hobo...@googlegroups.com
Hi Trond,

Here's a simple way with the default routes. In front_controller.rb add
this code:

def index
redirect_to Project.order("updated_at desc").first
end

I always mess up asc/desc with date fields, but something very similar
should work ;)

Regards,
Ignacio

El 11/11/13 10:59, Trond Lossius escribi�:
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre

Trond Lossius

unread,
Nov 11, 2013, 1:46:39 PM11/11/13
to hobo...@googlegroups.com
Thanks a lot, Ignacio,

That’s so much simpler than the various attempts that I made.

:-)

Best,
Trond


On 11 Nov 2013, at 19:41, Ignacio Huerta <ign...@ihuerta.net> wrote:

> Hi Trond,
>
> Here's a simple way with the default routes. In front_controller.rb add
> this code:
>
> def index
> redirect_to Project.order("updated_at desc").first
> end
>
> I always mess up asc/desc with date fields, but something very similar
> should work ;)
>
> Regards,
> Ignacio
>
> El 11/11/13 10:59, Trond Lossius escribió:
>> Hi,
>>
>> I have a Hobo app with a Projects model, containing among others a
>> :updated_at field. Now I'd like to redirect the front page of the app to
>> the Show page for the most recently updated project. I've tried several
>> different approaches fiddling around with Routes.rb and
>> projects_controller.rb, but so far to no avail. I guess that I'll need
>> to make a route to something like /projects/latest, and redirect front
>> to this, but I don't manage to find a way of doing so.
>>
>> Any suggestions for how to solve this would be highly appreciated!
>>
>> Thanks,
>> Trond
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Hobo Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to hobousers+...@googlegroups.com.
>> To post to this group, send email to hobo...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/hobousers.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> Ignacio Huerta Arteche
> http://www.ihuerta.net
> Teléfono: 0034 645 70 77 35
> Email realizado con software libre
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Hobo Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/hobousers/Xyqs-x9yT3Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to hobousers+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages