Saturday, 15 September 2012

ruby on rails - Rspec & Factory Girl: No route matches -


On a difficult journey to learn TDD with Exxpe, I did an error while testing the process of creating a controller for nested object Seen Comments are related to a post . I have not found any luck to find answers on stack overflow. Even I have so far away.

Examination.

comments_controller_spec.rb

  is required 'rails_helper' 'Shoulda-matchers' RSPC comment comments comment moderator, type => : Controllers first describe the 'create #GET': each @ post = factorial.Scent (post) Posted: Make, Comment: Attribute_for ((Comment, Post_ID: @ Post) In the end it 'makes a comment' Expecting (for comments) AEC (1) end and end  

failed. Failures: 1) Comments Controller # Gate Creates a Comment Failure / Error: Post: Create, Comment: Attributes_for (: Comment, Post_ID: Post) Action Controller :: URL Generation Error: No root matches {: action = & gt; "Create" ,: comment => {: Name = & gt; "MyStrin" :: Body = & gt; "MyText" ,: post_id = & gt; "1"} ,: Controller = & gt; "Comments"} # ./spec/controllers/comments_controller_spec.rb:9:in 'Block (Level 3) & lt; Top (required) & gt; '

comments_controller.rb

class commentsControler & lt; ApplicationController def can create @post = post.fund (param [: id]) @ comment = @ post quotations.credit (comment_prim) redirect @post and private df comment on param params.quare (comment). Permit (: name, body) End of End

routes.rb

  Route 'Post # Index' resource: Post resources are: Comments end  

rake routes

  ☹ rake routes prefix verb URI pattern controller # # Index Post_Mentts Received / Post /: Post_ID / Comment (.: Format) Comments # Index Post / Post / Post: / Post_ID / Comments (. Format:) Comments # Create new_post_comment GET /posts/.post_id/comments/new((.:format) Comments # New Edit_ Post_tamet Received / Post / Postpost_id / comments /: id / edit (.: Format) Comments # Edit post_comment GET / posts /.post_id/comments/:id(.:format) Comments # Show patch / posts / post :_it_id / comtem :((.format) Comments # Update / Post / Post: post_id / comments /: id (.: Format) Comments # Update Delit / Posts / Posts / Added / Comments /: Id (.: Format) Comments # Delete Posts Posts Obtain (.: Format) Post # Index Post / Post (. Format:) Post # Create News Post GET /posts/new(.:format) Post # New edit_post GET /posts/:id/edit(.:format ) Post # Edit Post / Post / :(((.:format) Post # Show Patch / Post /: ID (.: Format) Post # Update PUT /posts/:id(.:format) Post # Update Delay / Post / :( (.: Format) Post # Delete  

The problem is that You are sending parameters like this:

 : comment = & gt; {: Name = & gt; "MyString" ,: body = & gt; "MyText" ,: post_id = & gt; "1"}  

should be:

 : comment = & gt; {: Name = & gt; "MyString",: body = & gt; "MyText"} ,: post_id = & gt; "1"  

This route will be searched correctly.

For:

  Posted: Create, comment: attributes_for (: comment, post_ id: @ post)  

To: @ post = post.find (params [: post_id])


No comments:

Post a Comment