Hi all, I want to be able to display 404 page from a controller when a record in the database can not be found. I am using Rails 3 at the moment. I tried to find how to do this on guides.rails.info with no luck. Can anybody recommend the best approach to do this? Thanks heaps for your help and assistance. I really appreciate it. Kind regards, Joshua -- http://twitter.com/scrum8 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting Joshua Partogi <joshua.partogi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Hi all, > > > I want to be able to display 404 page from a controller when a record > in the database can not be found. I am using Rails 3 at the moment. I > tried to find how to do this on guides.rails.info with no luck. Can > anybody recommend the best approach to do this? >Have you tried raising ActiveRecord::NotFound in the controller? Or just let the model raise it. Jeffrey P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and 2.x. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Do you mean rescuing or raising ActiveRecord::NotFound? On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > Hi all, > > > I want to be able to display 404 page from a controller when a record > > in the database can not be found. I am using Rails 3 at the moment. I > > tried to find how to do this on guides.rails.info with no luck. Can > > anybody recommend the best approach to do this? > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > the model raise it. > > Jeffrey > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > 2.x.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Hi Jeff and Mirko, Thank you very much for the response. By default active_record will raise ActiveRecord::NotFound exception when a record can not be found in the database. And when this occurs, it will display the 404 page from the public folder. Unfortunately this hasn''t been working for me in production. After observing the problems, it seems it only occurs when running Rails 3 with passenger. I have tried the same test case but running Rails on thin and everything works as it should be. Does anybody have this kind of experience like this? Thanks very much in advance for sharing. Kind regards, Joshua On Jun 1, 3:10 am, Mirko <batam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Do you mean rescuing or raising ActiveRecord::NotFound? > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > Hi all, > > > > I want to be able to display 404 page from a controller when a record > > > in the database can not be found. I am using Rails 3 at the moment. I > > > tried to find how to do this on guides.rails.info with no luck. Can > > > anybody recommend the best approach to do this? > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > the model raise it. > > > Jeffrey > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > 2.x. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Jeffrey L. Taylor
2010-Jun-01 14:02 UTC
Re: Re: Showing 404 page from controller in Rails 3
Raising. In Rails 1.x and 2.x, ActiveRecord:NotFound exception is caught by Rails and it displays the 404 page. HTH, Jeffrey Quoting Mirko <batamire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Do you mean rescuing or raising ActiveRecord::NotFound? > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Hi all, > > > > > I want to be able to display 404 page from a controller when a record > > > in the database can not be found. I am using Rails 3 at the moment. I > > > tried to find how to do this on guides.rails.info with no luck. Can > > > anybody recommend the best approach to do this? > > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > the model raise it. > > > > Jeffrey > > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > 2.x.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
What does one do when he''s not using ActiveRecord? (Sequel here.) On Jun 1, 10:02 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> Raising. In Rails 1.x and 2.x, ActiveRecord:NotFound exception is caught by > Rails and it displays the404page. > > HTH, > Jeffrey > > Quoting Mirko <batam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > Do you mean rescuing or raising ActiveRecord::NotFound? > > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Hi all, > > > > > I want to be able to display404page from a controller when a record > > > > in the database can not be found. I am using Rails 3 at the moment. I > > > > tried to find how to do this on guides.rails.info with no luck. Can > > > > anybody recommend the best approach to do this? > > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > > the model raise it. > > > > Jeffrey > > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > > 2.x.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Jeffrey L. Taylor
2010-Jun-03 08:43 UTC
Re: Re: Showing 404 page from controller in Rails 3
Try "raise ActiveRecord::NotFound" or "render ''/404.html''". Jeffrey Quoting Legato <sireleo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> What does one do when he''s not using ActiveRecord? (Sequel here.) > > On Jun 1, 10:02 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > Raising. In Rails 1.x and 2.x, ActiveRecord:NotFound exception is caught by > > Rails and it displays the404page. > > > > HTH, > > Jeffrey > > > > Quoting Mirko <batam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Do you mean rescuing or raising ActiveRecord::NotFound? > > > > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > Hi all, > > > > > > > I want to be able to display404page from a controller when a record > > > > > in the database can not be found. I am using Rails 3 at the moment. I > > > > > tried to find how to do this on guides.rails.info with no luck. Can > > > > > anybody recommend the best approach to do this? > > > > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > > > the model raise it. > > > > > > Jeffrey > > > > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > > > 2.x. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I can''t raise ActiveRecord::NotFound as that''s not the ORM I am using, so it is not even require''d in my project. Rendering 404.html should work, but how do I halt the action additionally? raising an Exception will prevent the rest of the action from executing, but rendering won''t afaik. On Jun 3, 4:43 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> Try "raise ActiveRecord::NotFound" or "render ''/404.html''". > > Jeffrey > > Quoting Legato <sire...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > What does one do when he''s not using ActiveRecord? (Sequel here.) > > > On Jun 1, 10:02 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > Raising. In Rails 1.x and 2.x, ActiveRecord:NotFound exception is caught by > > > Rails and it displays the404page. > > > > HTH, > > > Jeffrey > > > > Quoting Mirko <batam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Do you mean rescuing or raising ActiveRecord::NotFound? > > > > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > Hi all, > > > > > > > I want to be able to display404page from a controller when a record > > > > > > in the database can not be found. I am using Rails 3 at the moment. I > > > > > > tried to find how to do this on guides.rails.info with no luck. Can > > > > > > anybody recommend the best approach to do this? > > > > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > > > > the model raise it. > > > > > > Jeffrey > > > > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > > > > 2.x. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Jeffrey L. Taylor
2010-Jun-06 00:43 UTC
Re: Re: Showing 404 page from controller in Rails 3
if <condition> render ''/404.html'' return end Quoting Legato <sireleo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> I can''t raise ActiveRecord::NotFound as that''s not the ORM I am using, > so it is not even require''d in my project. Rendering 404.html should > work, but how do I halt the action additionally? raising an Exception > will prevent the rest of the action from executing, but rendering > won''t afaik. > > On Jun 3, 4:43 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > Try "raise ActiveRecord::NotFound" or "render ''/404.html''". > > > > Jeffrey > > > > Quoting Legato <sire...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > What does one do when he''s not using ActiveRecord? (Sequel here.) > > > > > On Jun 1, 10:02 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > > Raising. In Rails 1.x and 2.x, ActiveRecord:NotFound exception is caught by > > > > Rails and it displays the404page. > > > > > > HTH, > > > > Jeffrey > > > > > > Quoting Mirko <batam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > Do you mean rescuing or raising ActiveRecord::NotFound? > > > > > > > On Jun 1, 4:54 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote: > > > > > > Quoting Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > > > Hi all, > > > > > > > > > I want to be able to display404page from a controller when a record > > > > > > > in the database can not be found. I am using Rails 3 at the moment. I > > > > > > > tried to find how to do this on guides.rails.info with no luck. Can > > > > > > > anybody recommend the best approach to do this? > > > > > > > > Have you tried raising ActiveRecord::NotFound in the controller? Or just let > > > > > > the model raise it. > > > > > > > > Jeffrey > > > > > > > > P.S. not actually tried this in Rails 3, this works for me in Rails 1.x and > > > > > > 2.x. > > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.