[Catalyst] [Beginner] Understanding actions and controllers - not!
Hi. Somewhen over the weekend I had the impression that I em beginning to understand how actions and controllers work. I was wrong. Starting with a bare minimum project, only using the standard root controller with three standard subs: index, default, end. I created a view, then set up an 'index.tt' template, as well as a 'error404.tt' template. index.tt contains the following line (via a wrapper): In the default action sub I have $c->stash->{template} = 'error404.tt'; Using: /localhost:3000/ -> renders index.tt nicely /localhost:3000/foo -> renders error404.tt nicely /localhost:3000/foo/bar -> renders error404.tt broken, the css file is not found! The debug screen says: [info] *** Request 12 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] *** [debug] "GET" request for "foo/bar" from "127.0.0.1" [debug] Path is "/" [debug] Arguments are "foo/bar" [debug] Rendering template "error404.tt" [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content- Length: 3861 [info] Request took 0.100899s (9.911/s) [...] [info] *** Request 13 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] *** [debug] "GET" request for "foo/static/css/main.css" from "127.0.0.1" [debug] Path is "/" [debug] Arguments are "foo/static/css/main.css" [debug] Rendering template "error404.tt" [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content- Length: 3877 [info] Request took 0.101907s (9.813/s) [...] The default sub is declared as: sub default :Path { What am I missing here? Why is the first pathpart (1st argument) now suddenly prepended to my static path? All templates are in the same directory under root/ TIA, Ekki ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
try using /static/css/main.css ;) Ekki Plicht (DF4OR) wrote: Hi. Somewhen over the weekend I had the impression that I em beginning to understand how actions and controllers work. I was wrong. Starting with a bare minimum project, only using the standard root controller with three standard subs: index, default, end. I created a view, then set up an 'index.tt' template, as well as a 'error404.tt' template. index.tt contains the following line (via a wrapper): In the default action sub I have $c->stash->{template} = 'error404.tt'; Using: /localhost:3000/ -> renders index.tt nicely /localhost:3000/foo -> renders error404.tt nicely /localhost:3000/foo/bar -> renders error404.tt broken, the css file is not found! The debug screen says: [info] *** Request 12 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] *** [debug] "GET" request for "foo/bar" from "127.0.0.1" [debug] Path is "/" [debug] Arguments are "foo/bar" [debug] Rendering template "error404.tt" [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content- Length: 3861 [info] Request took 0.100899s (9.911/s) [...] [info] *** Request 13 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] *** [debug] "GET" request for "foo/static/css/main.css" from "127.0.0.1" [debug] Path is "/" [debug] Arguments are "foo/static/css/main.css" [debug] Rendering template "error404.tt" [debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content- Length: 3877 [info] Request took 0.101907s (9.813/s) [...] The default sub is declared as: sub default :Path { What am I missing here? Why is the first pathpart (1st argument) now suddenly prepended to my static path? All templates are in the same directory under root/ TIA, Ekki ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
I've tended to use: I guess it depends on how it's being hosted, but I couldn't assume the top level URL space, so a straight absolute URL seemed a risk. All the best Stuart -- Stuart Watt ARM Product Developer Information Balance On 8/23/2010 5:17 PM, Ben van Staveren wrote: try using /static/css/main.css ;) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
Am Montag 23 August 2010, 23:17:40 schrieb Ben van Staveren: > try using /static/css/main.css ;) Yup, that did the trick. $c.uri_for() would have worked as well, as I have learned now (tnx Stuart). But why? :-) I mean, coming from years of traditional web development it's deeply ingrained not to use absolute paths. I would never have expected to have Cat meddle with my views in such a way. Anyway, it works now, and I am progressing quite nicely. Catalyst seems more and more impressive to me. Cheers, Ekki ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
On 27/08/2010, at 7:50 AM, Ekki Plicht (DF4OR) wrote: > Am Montag 23 August 2010, 23:17:40 schrieb Ben van Staveren: >> try using /static/css/main.css ;) > > Yup, that did the trick. > $c.uri_for() would have worked as well, as I have learned now (tnx Stuart). $c->uri_for('/static/wherever') is the correct solution. Giving it an absolute path will most likely break if you end up deploying your application somewhere other than the server root. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
Am Freitag 27 August 2010, 00:02:15 schrieb Kieren Diment: > On 27/08/2010, at 7:50 AM, Ekki Plicht (DF4OR) wrote: > > Am Montag 23 August 2010, 23:17:40 schrieb Ben van Staveren: > >> try using /static/css/main.css ;) > > > > Yup, that did the trick. > > $c.uri_for() would have worked as well, as I have learned now (tnx > > Stuart). > > $c->uri_for('/static/wherever') is the correct solution. Giving it an > absolute path will most likely break if you end up deploying your > application somewhere other than the server root. k, tnx. Good book, BTW :-) Cheers, Ekki ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] [Beginner] Understanding actions and controllers - not!
I'm catching up on list mailings, so I'm sorry about the delay on this response. I think an important point was overlooked here... On Thu, Aug 26, 2010 at 5:50 PM, Ekki Plicht (DF4OR) wrote: > Am Montag 23 August 2010, 23:17:40 schrieb Ben van Staveren: > > try using /static/css/main.css ;) > > Yup, that did the trick. > $c.uri_for() would have worked as well, as I have learned now (tnx Stuart). > > But why? :-) > I mean, coming from years of traditional web development it's deeply > ingrained > not to use absolute paths. I would never have expected to have Cat meddle > with > my views in such a way. > This problem is not caused by Catalyst. The document you're returning to the browser contains a relative path to the CSS file: The browser looks for that relative to the location of the current page. If the URL of the current page is http://www.example.com/foo/bar, then the browser expects to find your stylesheet at http://www.example.com/foo/static/css/main.css. Ronald ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/