im pretty much a rails newbie, but i was wondering where the rhtml
files go for the application controller?
i.e. if i had some logic that needed to be performed on the document
root of my website: (i.e. http://www.mysite.com)
where would i put this rhtml file.
I tried putting it in the public directory, but that failed...and the
content inside the <% %> takes weren't evaluated...
also, just entering http://www.mysite.com didn't automatically render
index.rhtml, but rather gave me a 404 error.
map.connect ‘:controller/:action/:id.:format’
map.connect ‘:controller/:action/:id’
end
As you can see the first uncommented line is
map.connect ‘’, :controller => “welcome”
What this tells rails is that when the url is only http://www.mysite.com it should route that request to the welcome controller. If no action is specified rails will default to calling the index action in that controller. The index action will look for an index.rhtml, parse the <% %> into the appropriate html and deliver a html file to be served to the browser.
The last uncommented line which looks like this
map.connect ‘:controller/:action/:id’
is the default decoding of urls. the routing expects a url that looks like this for example:
http://www.mysite.com/welcome/show/5
This route mapping “decodes” the url as
:controller => ‘welcome’
:action => ‘show’
:id => 5
thanks to both of you...thats clears things up a lot, i will start
playing with it first chance i get.
To delve a bit deeper about the structure of a rails app, is it bad
design to have only an application.rb controller? and so other
controllers.
Let me explain a bit more, basically, the site i am working on has a
lot of cgi script (thats the main chunk of the features this site
promotes), and I have the task of adding user accounts to this site
for a small additional feature. basically, at this point in time, it
seems like this will be the only feature rails will be in charge
of....so i am left wondering whats the point of putting all of my
logic in an AccountController, and having an empty
Application.rb...maybe it would make the most sense to just have
everything inside the application controller, and shorten my urls at
the same time (i.e. http://www.mysite.com/login vs. http://www.mysite.com/account/login).
This first hit me when i was adding the rails code to existing html
pages, i found that i needed to add a '../' before the images
directory in all of my <img> tags because of the fact that i was up a
level (i.e. in the account controller)