Hi All,
I am going through Patrick Lenz's 'Build your own Ruby on Rails Web Apps' and i have an issue with adding new 'stories'.

I appear to add the story fine, but when i look in the database, the permalink field for all the new stories has 'null' and randomly when i refresh my story page (which should show a random link to a story) sometimes it throws error:

ActionController::RoutingError in Story#index
story_url failed to generate from {:controller=>"story", :action=>"show", :permalink=>nil}, expected: {:controller=>"story", :action=>"show"}, diff: {:permalink=>nil}
Extracted source (around line #2):
1: link:
2: <%= link_to @story.name, story_url(:permalink => @story.permalink) %>

Which i am assuming is when it is trying to access one of the stories that doesn't have a permalink entry in the database.
Any ideas as to why it isn't adding the permalink entry to the database?

This is what i have done (copied straight from the book):
  • added the routing as stated, just after the first map.connect
    map.story 'story/show/:permalink', :controller => 'story', :action => 'show'
  • setup and run the migrate file
    class AddPermalinkToStories < ActiveRecord::Migration
    def self.up
    add_column :stories, :permalink, :string
    def self.down
    remove_column :stories, :permalink
  • and added the show method to the story_controller
    def show
    @story = Story.find_by_permalink(params[:permalink])

Is there something more I need to do? Any help would be appreciated :)

Thanks in advance,