ruby on rails - No route matches {:action=>"/microposts", :controller=>"microposts", :params=>{:micropost=>{:content=>"Lorem ipsum"}}} -


i stuck on rails tutorial michael hartl (railstutorial.org), chapter 13

and getting following 2 errors:

1) error: micropostscontrollertest#test_should_redirect_create_when_not_logged_in: actioncontroller::urlgenerationerror: no route matches {:action=>"/microposts", :controller=>"microposts", :params=>{:micropost=>{:content=>"lorem ipsum"}}}     test/controllers/microposts_controller_test.rb:11:in 'block (2 levels) in <class:micropostscontrollertest>'     test/controllers/microposts_controller_test.rb:10:in 'block in <class:micropostscontrollertest>'     2) error: micropostscontrollertest#test_should_redirect_destroy_when_not_logged_in: actioncontroller::urlgenerationerror: no route matches {:action=>"/microposts/499495288", :controller=>"microposts"}     test/controllers/microposts_controller_test.rb:18:in 'block (2 levels) in <class:micropostscontrollertest>'     test/controllers/microposts_controller_test.rb:17:in 'block in <class:micropostscontrollertest>' 

as far know, 'action' should get, post, delete etc. don't know, why says 'micropost' here.

content of microposts_controller_test.rb:

require 'test_helper'  class micropostscontrollertest < actioncontroller::testcase    def setup     @micropost = microposts(:orange)   end    test 'should redirect create when not logged in'     assert_no_difference 'micropost.count'       post microposts_path, params: {micropost: {content: 'lorem ipsum'}}     end     assert_redirected_to login_url   end    test 'should redirect destroy when not logged in'     assert_no_difference 'micropost.count'       delete micropost_path(@micropost)     end     assert_redirected_to login_url   end end 

content of micropost_controller.rb:

class micropostscontroller < applicationcontroller   before_action :logged_in_user, only: [:create, :destroy]    def create     @micropost = current_user.microposts.build(micropost_params)     if @micropost.save       flash[:success] = 'micropost created!'       redirect_to root_url     else       render 'static_pages/home'     end   end    def destroy   end    private    def micropost_params     params.require(:micropost).permit(:content)   end  end 

content of routes.rb:

rails.application.routes.draw   root 'static_pages#home'   '/help' => 'static_pages#help'   '/about' => 'static_pages#about'   '/contact' => 'static_pages#contact'   '/signup' => 'users#new'   '/login' => 'sessions#new'   post '/login' => 'sessions#create'   delete '/logout' => 'sessions#destroy'   resources :users   resources :account_activations, only: [:edit]   resources :password_resets, only:     [:new, :create, :edit, :update]   resources :microposts, only:           [:create, :destroy] end 

any appreciated.

thanks

edit:

in micropost_controller_test.rb, should've been:

class micropostscontrollertest < actiondispatch::integrationtest 

instead of

class micropostcontrollertest < actioncntroller::testcase 

the problem first test dont have route in controller /microposts" on test trying hit , if see routes file confirms resources :microposts, only: [:create, :destroy], no route that. secondly after destroy should redirect , in controller method no redirection there. test fails.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -