SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member rolomite's Avatar
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby on Rails problem Page 164

    Im not able to get the book result after adding the New Resource

    ActionController::Routing::Routes.draw do |map|
    map.resources :stories
    map.connect ':controller/:action/:id'
    map.connect ':controller/:action/:id.:format'
    end

    I'm getting the following error on the browser:

    Routing Error

    No route matches "/stories/new" with {:method=>:get}

    Can anyone please help me and tell me what's the issue here, what do I need to do to get past this point.

    thanks

    - rolomite

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,238
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Hi rolomite, welcome to the forums,
    Did you create a new.html.erb file in the app/views/stories folder (page 159)?

  3. #3
    SitePoint Member rolomite's Avatar
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Mittineague,

    I created all the new.html.erb file and I currently have the following content in it:

    <&#37; form_for @story do |f| %>
    <p>
    namebr />
    <%= f.text_field :name %>
    </p>
    <p>
    linkbr />
    <%= f.text_field :link %>
    </p>
    <p>
    <%= submit_tag %>
    </p>
    <% end %>

    thanks for the fast reply and help.

    - rolomite

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,238
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    And your app\controllers\stories_controller.rb file looks like this?
    Code Ruby:
    class StoriesController < ApplicationController
      def index
        @story = Story.find(:first, :order => 'RANDOM()')
      end
     
      def new
        @story = Story.new
      end
    end

    If you
    Code:
    ..shovell>ruby script/console
    ......
    >>Story.find(:all)
    Do you see something like
    Code:
    => [#<Story id: 1, name: "My shiny webblog", link: "http://poocs.net
    /", created_at: "2008-08-25 21:42:08", updated_at: "2008-08-25 21:51:53">, #<Sto
    ry id: 2, name: "SitePoint Forums", link: "http://www.sitepoint.com/forums/", cr
    eated_at: "2008-08-25 21:44:25", updated_at: "2008-08-25 21:44:25">]

  5. #5
    SitePoint Member rolomite's Avatar
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mittineague,

    My stories_controller_rb looks just how you have listed, ad I also got the result listed for the execution of Story.findall)

    I'm still having the same problem

    No route matches "/stories/new" with {:method=>:get}

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,238
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Hmmm.

    If you do
    Code:
    ..shovell>rake routes
    you should see output like
    Code:
    troller=>"stories", :action=>"new"}
                   edit_story GET    /stories/:id/edit                         {:co
    troller=>"stories", :action=>"edit"}
         formatted_edit_story GET    /stories/:id/edit.:format                 {:co
    troller=>"stories", :action=>"edit"}
                        story GET    /stories/:id                              {:co
    troller=>"stories", :action=>"show"}
              formatted_story GET    /stories/:id.:format                      {:co
    troller=>"stories", :action=>"show"}
                              PUT    /stories/:id                              {:co
    troller=>"stories", :action=>"update"}
                              PUT    /stories/:id.:format                      {:co
    troller=>"stories", :action=>"update"}
                              DELETE /stories/:id                              {:co
    troller=>"stories", :action=>"destroy"}
                              DELETE /stories/:id.:format                      {:con
    troller=>"stories", :action=>"destroy"}
    Please post your results (use the [CODE] bbtags or disable smilies, please).

    EDIT: While you're at it. if you go to
    http://localhost:3000/index.html
    and click
    About your application’s environment
    you should see something like
    Ruby version 1.8.6 (i386-mswin32)
    RubyGems version 0.9.4
    Rails version 2.1.0
    Active Record version 2.1.0
    Action Pack version 2.1.0
    Active Resource version 2.1.0
    Action Mailer version 2.1.0
    Active Support version 2.1.0
    Application root C:/ruby/shovell
    Environment development
    Database adapter sqlite3
    Database schema version 20080827135856
    Please post that too.

  7. #7
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Hey I could see all the above. But still I am facing the same error.

    --------------------------------------------------
    No route matches "/story" with {:method=>:get}
    ---------------------------------------------------

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it's not /story it's /stories if you wanna trigger index action

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,238
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Yes, If I startup the script/server at point my browser to
    http://localhost:3000/story
    I get
    Routing Error
    No route matches "/story" with {:method=>:get}

    http://localhost:3000/stories
    should work OK no? And
    http://localhost:3000/stories/new
    ??

  10. #10
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your routes.rb contains:

    Code Ruby:
    map.resources :stories

    Then, yes, I would expect localhost:3000/story to produce a routing error.

    localhost:3000/stories and localhost:3000/stories/new should work though, yes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •