开发者

Beginner with Rails 3.1 and "static" pages

I just started deploying a Rails website. In fact, I started programming on Rails 2 days ago. I've created a new project, added some gems, etc. Everything is working properly, and I have some basic knowledge on how all works.

The thing is that what I want to create is a simple website with some sections (let's say, News, Contact, About, Products...). All this content is kinda static.

But I came in a problem. I don't really know what to do in order to create them. What I want, for example, is something like mypage.开发者_StackOverflow社区com/products/fashionableproduct, mypage.com/about, etc, or even mypage.com/page/products.

I thought about creating a Controller, then an action for each page... afterwards, I came up with other solution: scaffolding. Creating a resource called page, that has a title, etc...

I'm really a beginner on this topic, and I would like to hear your helpful voice. Thanks!


Check out https://github.com/thoughtbot/high_voltage for static pages for Rails.

And check out http://railscasts.com/episodes/30-pretty-page-title for setting page titles.


The paths to your files are determined by your routes. The configuration file for routes is located at config/routes.rb. You can match a URL path, and then point to a given resource. More information about routes here: http://guides.rubyonrails.org/routing.html

If you generate a controller, you can process any dynamic data and then pass this data to these "kinda static" pages. Here is an example configuration that would match the path "mypage.com/about" and display the appropriate page:

# config/routes.rb
match "/about" => "example_controller#about"

# app/controllers/example_controller.rb
class ExampleController < ApplicationController
  def about
    # calculations
  end
end

# app/views/example/about.html.erb
<!-- This is your HTML page -->


I think the title of your post might be a bit misleading. I have the feeling you don't want static pages but some database stored content. Just like Ben Simpson tells you to do, create a normal pages controller and make it work.

In the end you might want to customize some routes to get them to be exactly the way you want as in your examples.

Since you just started the app, I strongly recommend you start over and make a new app with Rails 3.1 which is the most current version and learn how to do the basics through http://guides.rubyonrails.org/ and a few other sources such as http://railscasts.com.

You will then learn Rails the right way from the beginning. Good luck and have fun in the process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜