Topic: Routing problem

New to ruby here, I use windows 7 and using rails installer.

Currently I just learning from podcast, and I encounter this problem.

At first, I create a controller by using

rails generate model Subscriber

and then create a controller by using

rails generate controller Subscribers

and then I modify my controller into

class SubscribersController < ApplicationController
 
  def create
    if request.post?
      @subscriber = Subscriber.new(:email => params[:email])
      if @subscriber.save
        @success = "Thank you, You have been subsribed."
      else
        @error = @subscriber.errors.full_messages[0]
      end
    end
  end

end


and then i create the create.html.erb at the view folder

supposedly according to the tutorial I should be able to access it on localhost:3000/subscribers/create
but I got the following message instead

Routing Error

No route matches "/subscribers/create"

So i tick around and add a litle line into my routes.rb

get "subscribers/create"

and it is showing the page properly, however when I submit the form it's showing the routing error message again.

Anyone know where I did wrong? pretty sure I followed everything step by step that mentioned on the podcast but the result is very different sad

Re: Routing problem

Which version of Rails are you using? And what is the output when you do a "Rake routes"?

Also, take a look at this Rails Guide regarding routes and resources (especially section 2.2):
http://guides.rubyonrails.org/routing.html

I'll also point out that I don't think you should be routing directly to the create action like that. Convention is for the create to receive a POST as mentioned in the article linked to above.

The create action works in tandem with the new action. For example, you could have a form at /subscribers/new, and on submit the form sends a POST to the create action. These routes can all be set up for you if you put "resources :subscribers" in your routes.rb file.

Last edited by Brian71 (2012-05-03 10:13:00)

Re: Routing problem

Hi brian, I was using rails 3.011 and I just upgraded to 3.2.1 but unfortunately same problem still exist sad

I try to use rake routes but it doesn't return me anything, no message or whatever

and regarding the routing I am still just starting rails so I don't really know about it yet. I just merely following example of the podcast.

Re: Routing problem

Run the following in your console:

rake routes blah

If you still do not receive an error or any message at all, then there is something wrong with your configuration. However, if you do get an error, run the normal "rake routes" and wait a few minutes. If nothing comes up still, let me know.

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!