Related Link

Archive for the ‘Ruby on Rails’ Category

Permalinks

Posted in Ruby on Rails, Web Design

A permalink is an attribute of a Story, so we’ll need to modify our schema so that one can be stored for each story. We’ve already seen migrations in action each of our existing migrations was generated when we created a new model. Now we need to expand an existing model, so that we can add a permalink attribute to the Story model.

To add a migration without adding a new model, we use the generate script, passing migration as the first parameter:
$ ruby script/generate migration AddPermalinkToStories
(more…)

URLs

Posted in Ruby on Rails, Web Design

In terms of viewing our sites, our users currently only have access to a page that displays a random story. To address this issue, we’ll add a new action that displays a single story, along with all of its details, before we implement the voting actions themselves. The story page will serve as a reference point for any given story on the site, as it will contain a range
of information voting actions, voting history, and so on about the story. Before we dive into the creation of our story page, let’s take a quick but important detour. The development of a story page such as this provides the perfect opportunity for a discussion about clean URLs.

Rails translates URLs of a certain format into actions that are invoked on a controller class. The translation, known as routing, is performed by the Rails Routing module.
Consider a URL that has the following format:

http://domain.com/story/show/1

(more…)

Creating a View

Posted in Ruby on Rails, Web Design

After creating a model and a controller, then its time for us to create a view. We can use two approaches to build views for our Rails application. One is to make use of scaffolding; the other is to “go it alone.” We’ll look at scaffolding very briefly, but we won’t be using it much in the development of our Shovell application. I’ll introduce just enough to give you a taste
of this topic, then leave it up to you to decide whether or not you find it worthwhile in your own projects.

Generating Views with Scaffolding
In the early days of Rails, scaffolding was one of the features that the Rails community used as a selling point when promoting the framework. Ironically, this feature also received a considerable amount of criticism, though this was
largely due to critics failing to understand fully the intended uses of scaffolding.
(more…)

Generating a controller

Posted in Ruby on Rails, Web Design

Now that we have our model in place (refer to previous article: Generating a model on Ruby), let’s build a controller. In the same way that we generated a model, we generate a controller by running the script/generate script from our application’s root folder.

Run the generate script from the command line again, but this time, pass controller as the first parameter:
$ ruby script/generate controller


(more…)

Generating a model in Ruby

Posted in Ruby on Rails, Web Design

In previous articles we had discussed and introduced the principles behind the model-view-controller architectural pattern, and saw how each of the components is implemented within the Rails framework. Now lets use those knowledge on Rails’s code generation techniques to create components.

generate can be called from the command line and takes several parameters. The first parameter is the type of component that’s to be generated. You can probably guess which value I’m going to suggest you use for this parameter. We’re creating a model, so the parameter to pass is simply model. Let’s take a look at what happens when we pass that to the script: (more…)

Favorite Link