Reputation: 10358
Here is code in index.html.erb:
<%= link_to 'Back', '/url_handler?url=@return_to&index=0' %>
Here is the mapping for /url_handler in routes.rb:
match '/url_handler', :to => 'application#url_handler'
Here is the code for url_handler in application controller:
def url_handler
url = params[:url]
index = params[:index]
if index == 1 then
step_forward(url)
elsif index == 0 then
step_back
end
redirect_to url
end
private
#record path to current page
def step_forward(current_path)
session[:page_step] += 1
session[('page' + session[:page_step].to_s).to_sym] = current_path if session[:page_step] > 1
end
#return link for previous page in page step
def step_back
session[:page_step] -= 1
end
The problem is that 2 params in url_handler does not retrieve the @return_to and 0 passed along in index.html.erb. @return_to has a valid value in it when passed along.
Any solutions for the problem? Thanks.
Upvotes: 0
Views: 69
Reputation: 20614
<%= link_to 'Back', '/url_handler?url=@return_to&index=0' %>
Should be
<%= link_to 'Back', "/url_handler?url=#{@return_to}&index=0" %>
Note double quotes and return_to
Check your log file log/development.log to see what values are passed in params
Upvotes: 1