mercredi 25 juillet 2018

Rails goes to show action when I want custom action of open or expired

I am basically trying to do a custom index In my routes.rb I have:

resources :tokens do
  resources :visits
  collection do 
    get :open
    get :expired
  end
end

My routes show as :

 open_tokens GET    /tokens/open(.:format)                                 tokens#open
 expired_tokens GET    /tokens/expired(.:format)                              tokens#expired

I have open and expired defined in my tokens controller

 def open

       @q = Token.open_token.includes(:households, :visits).search(params[:q])
    @tokens = @q.result

       respond_to do |format|
       format.html {render template: 'tokens/open'}
       end
  end

   def expired

  @q = Token.expired_token.includes(:households, :visits).search(params[:q])
    @tokens = @q.result

  respond_to do |format|
      format.html {render template: 'tokens/expired'}
   end
  end

But it goes to my show controller with the following error:

Couldn't find Token with id=open

and it crashes at my Show action:

Better Errors shows the request as:

{"action"=>"show", "controller"=>"tokens", "id"=>"open"}

It seems to me that the action should be open with no parameters

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire