I'm trying to figure out why my link_to isn't working how I thought it would. In my application, I have a database of prizes. When a user clicks on the link_to, the controller should access the selected action (in this case, "result1") and perform the action's method on the resultpage view. From testing, it appears as if the link_to is completely ignoring the :action => 'result1' and just defaults to doing the Show method.
Any idea why the link_to is completely ignoring the :action => 'result1'?
First View: views/start/start.html.erb view:
<%=link_to 'result', resultpage_path, :controller => 'resultpage', :action => 'result1', :class => 'btn btn-default'%>
Resultpage Controller: controllers/resultpage_controller.rb
class ResultpageController < ApplicationController
def index
end
# regardless of what is in the :action =>, the controller always calls Show.
def show
@prize = Prize.first
render :index
end
# if i make the :action => 'result1', the controller still calls Show.
def result1
@prize = Prize.last
render :index
end
Results View: resultspage/index.html.erb
<h2><%= @prize.title %></h2>
<p><%= @prize.description %></p>
Routes:
resources :resultpage do
get 'index'
get 'show'
end
resources :prizes
Make routes with such content
Use such link
And modify tour controller
And, BTW read this article carefully