Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails simple page without database model

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?

like image 819
Johan Avatar asked Dec 29 '22 09:12

Johan


1 Answers

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>
like image 124
jvnill Avatar answered Jan 11 '23 09:01

jvnill