undefined method?

I'm trying to learn rails as I go along, and having a bit of trouble. There is an undefined method cropping that I don't know why rails thinks should be there.

Firstly, I'm using rails 3, ruby 1.9.2

I have a controller with an index action This part works fine, but i am trying to add a comment form to the page that is rendered by that index action.

Supposing my controller is named controller1,

I began this process first with:

rails g model comments name:string content:text rake rb:migrate

Then I went on to define an action to create the comments:

within contoller1_controller.rb I added

You were using a singular resource when you should have defined a plural one. Also, you can specify the controller on your RESTful route instead of having to create a separate map.connect or match:

resources :comments, :controller => 'controller1'

I recommend that you use consistent naming with your controllers and routes though.

HTH

I'm still getting the "undefined method `comments_index_path'" error

The extracted source points at:   <%= form_for(@comment) do |format| %>

I cannot find where that method would be being called from even..."comments_index_path" only appears in the development.log

Hmmm wait, I just noticed something. Could you rename your Comments model to Comment (from plural to singular). Don't forget to rename the model file (comments.rb to comment.rb)

Thanks, that gets the comment form loading.

I added:

  def create     @comment = Comment.new(params[:comments])

    respond_to do |format|       if @comment.save         format.html { redirect_to('/', :notice => 'comment posted') }         format.xml { render :xml => @comment, :status => :created, :location => @comment }       else         format.html { render :action => "new" }         format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }       end     end   end

to my controller1_controller.rb file, and now when I click the submit button, I get the following error "uninitialized constant CommentsController"

Despite the redirect_to('/', ...) the page is redirecting to /comments

Can you post your route setup again?

Internet::Application.routes.draw do |map|   get "internets/index"   get "section4/index"   get "section3/index"   get "section2/index"   get "section1/index"   get "science/index"   resources :users   resources :comments   map.connect '/blog/new', :controller => 'section3', :action => 'new'   get 'login(.:format)' => 'user_session#new', :as => :login   post 'login(.:format)' => 'user_session#create', :as => :login   delete 'logout(.:format)' => 'user_session#destroy', :as => :logout   get "home/index"   root :to => "home#index"   map.logout 'logout', :controller => 'user_session', :action => 'destroy'   map.logout 'logout', :controller => 'user_session', :action => 'destroy'   map.edit 'edit', :controller => 'users', :action => 'edit'   map.internets 'internets', :controller => 'internets', :action => 'index'   map.section4 'random', :controller => 'section4', :action => 'index'   map.section3 'blog', :controller => 'section3', :action => 'index'   map.section2 'artistry', :controller => 'section2', :action => 'index'   map.section1 'home', :controller => 'section1', :action => 'index' end

Thats the entirety of it. The area that is giving me trouble is in the 'section3' controller

I can post comments from the console, and they do then show up in the index.

and when I use "form_for :comments" the log shows the data being posted, but there's no INSERT INTO being executed

It seems like the form is not reading from the controller

thanks for the help

I got it to work by creating a comments_controller.rb file and using the same action definitions as the section3_controller

I'm not sure why i had to make a new controller though.

But, thanks for the help