I'm a beginner of Ruby and Rails, so this is probably an easy question.
How should I set up a simple page that does not need to have any own database tables? In my case, for example, I have a site storing songs and artists. How I want just a simple HELP page with no intelligence, just static html. I also need a BROWSE page, where the user will select whether to browse for artists or songs. This page will not have any database tables, however it will have a list of links from A-Z, provided the number of posts for each letter, so therefore it needs to have database interaction for tables it does not own by itself.
Should I just create controllers for HELP and BROWSE, or will they need models as well? Using Rails 2, which script/generate tools should I use and what should I ask them to do for me?
I usually create a PagesController that shows the static pages like about, faq or privacy.
What you have to do is generate the controller by using
script/generate controller pages
then add the following in your config/routes.rb
map.resources :pages, :only => :show
In your PagesController
def show
# filter the params[:id] here to allow only certain values like
if params[:id].match /browse|help/
render :partial => params[:id]
else
render :file => "/path/to/some/404_template", :status => 404
end
end
Then you just need to add partials in app/views/pages/
#in /app/views/pages/_help.html.erb
<p>This is the help section</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With