Problem with auto-generated controller and index

Good day, people,
I installed a fully working Ruby on Rails on my Debian Squeeze system
today and am studying a tutorial about Ruby on Rails right now.
It says that in the main folder of my app, I should type

ruby script/generate controller Stories index

Good, but that seems to be for older ruby versions than mine. I get a
‘file not found’ error.
So I took a little look around the directory and found that I may use:

ruby script/rails generate controller Stories index

Now I get the following:

  create  app/controllers/stories_controller.rb
   route  get "stories/index"
  invoke  erb
  create    app/views/stories
  create    app/views/stories/index.html.erb
  invoke  test_unit
  create    test/functional/stories_controller_test.rb
  invoke  helper
  create    app/helpers/stories_helper.rb
  invoke    test_unit
  create      test/unit/helpers/stories_helper_test.rb

Good! Then it’s said that I should go to http://localhost:3000/stories
where I would find a quite empty starting page. But the only thing
I’ll get is

Routing Error
No route matches “/stories”

I thought for a second and typed in http://localhost:3000/stories/index
, and I get

Stories#index
Find me in app/views/stories/index.html.erb

Huh. That’s good for the time being, because something happens in some
kind and I got a functioning (at least halfway) controller. But why
won’t it use /stories/index just for the parent directory /stories –
and especially: Why doesn’t it do that as automatically by official
Ruby on Rails tools generated
code? Would look some kinda stupid when
every url of my website will have /index at the end. >:s

Regards,
Simon

On Mar 12, 11:25pm, Simon W. [email protected] wrote:

Stories#index
Find me in app/views/stories/index.html.erb

Huh. That’s good for the time being, because something happens in some
kind and I got a functioning (at least halfway) controller. But why
won’t it use /stories/index just for the parent directory /stories –
and especially: Why doesn’t it do that as automatically by official
Ruby on Rails tools generated
code? Would look some kinda stupid when
every url of my website will have /index at the end. >:s

You got exactly what you asked for - if you just ask for a controller
with an action, there’s no special casing of particular action names.
You can of course add a route specifying what should be done with /
stories. Typically you would be using resourceful routes, in which
cases /stories would be mapped to StoriesController#index for you.
(try rails generate scaffold stories name:string body:text)

Fred

Fred

On Mar 12, 11:25pm, Simon W. [email protected] wrote:

ruby script/rails generate controller Stories index

By the way, this implies that you’re working with rails 3 but
following a tutorial on rails 2.x (or earlier). Rails 3 is
substantially different from rails 2 - you might want to hunt for an
up to date tutorial. guides.rubyonrails.org is a good place to start

Fred

Thanks for your answer! I’m just a little bit disappointed now that I
have to use a whole other tutorial now.
scaffold will create all things for a basic database view and editing
system, and it will create

resources :stories

in my routes.rb. Well, that’s what I did manually now. I don’t wanna
have everything pre-done for me right now, although I think scaffold
will get useful for me again.

Thank you! :slight_smile:

On 13 Mrz., 11:56, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs