No action found

I want to show a simple HTML template, so I added a new blank action for my controller:

def calulator end 

And created view calculator.html.erb. Then added the link:

 <%= link_to 'Calculator', {:controller => "mycontroller", :action => "calculator"} %> 

When I click on it, the following error is displayed in my log:

 ActionController::UnknownAction (No action responded to show. Actions: calculator, create, destroy, edit, index, new, and update): 

Why are you looking for a show action? I have map.resources for the controller since I did this using forests

Any ideas?

+4
source share
3 answers

You need to add a custom route pointing to the "calculator" of the action. Something like that:

 map.connect 'mycontroller/calculator', :controller => 'mycontroller', :action => 'calculator' 
+5
source

You can define elements and collections for resources.

 map.resources :samples, :member => {:calculator => :get} 

A member means that it refers to an instance of resources. For example, / samples / 1 / calculator. If this does not apply to the instance, you can define it for the collection and access it through / samples / calculator.

 map.resources :samples, :collection => {:calculator => :get} 

It also creates the helper method calculator_samples_path for the collection and calculator_sample_path(sample) for the member. See the Railscast Episode 35 for more on this.

+1
source

You get a β€œNo action” message to show because you are controlling the controller as map.resources . When you do this, the rails set up several routes for you. One of them is show , which maps each request to receive the / mycontroller / somevalue request to the show action with some value like id ( params[:id] ). There mycontroller no show action in mycontroller , as seen from the error message.

To fix this, the Niels or Trevok response should work fine.

map.resources documentation

0
source

All Articles