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

On 10/14/10 5:53 PM, aperture science wrote:
> 
> 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
> =========
>   def new
>     @comment = Comments.new
> 
>     respond_to do |format|
>       format.html
>       format.xml { render :xml => @comment }
>     end
>   end
> ========
> 
> views/controller1/new.haml contains
> ========
> = render 'form'
> ========
> 
> and _form.html.erb contains
> ========
> <%= form_for(@comment) do |format| %>
> 
> <div class='commentForm'>
>   <%= format.label :name %><br />
>   <%= format.text_field :name %><br />
> 
>   <%= format.label :content %><br />
>   <%= format.text_area :content %><br />
>     <div class='commentSend'>
>       <%= format.submit %>
>     </div>
> </div>
> 
> <% end %>
> =======
> 
> I then added into routes.db the following lines:
> resource :comments
>   map.connect '/controller1/new', :controller =>
> 'controller1', :action => 'new'
> 
> 
> Now, navigating to /controller1/new gives me this error:
> 
> undefined method `comments_index_path'
> 
> 
> What am I missing?
> 
> If I change the form to "form_for(:Comments)", then '/controller1/new'
> renders, however, when I then add  "@comments = Comments.all" into the
> index definition, and:
>   - @comments.each do |comment|
>     - comment.content
> into the index.haml file, no comments are actually displayed. So I
> assume the form is not actually sending anything to the database
> 
> 
> Any tips on what I'm doing wrong would be greatly appreciated,
> 
> Thanks
> 

-- 
Erol Fornoles
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to