Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails params不检索erb中传递的任何内容_Ruby On Rails_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails params不检索erb中传递的任何内容

Ruby on rails params不检索erb中传递的任何内容,ruby-on-rails,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3.1,以下是index.html.erb中的代码: <%= link_to 'Back', '/url_handler?url=@return_to&index=0' %> 以下是应用程序控制器中url_处理程序的代码: def url_handler url = params[:url] index = params[:index] if index == 1 then step_forward(url) elsif

以下是index.html.erb中的代码:

  <%= link_to 'Back', '/url_handler?url=@return_to&index=0' %>
以下是应用程序控制器中url_处理程序的代码:

  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
问题是url_处理程序中的2个参数没有检索index.html.erb中传递的@return_to和0@传回时,return_to中有一个有效值

这个问题有什么解决办法吗?谢谢。


<%= link_to 'Back', '/url_handler?url=@return_to&index=0' %>
应该是

<%= link_to 'Back', "/url_handler?url=#{@return_to}&index=0" %>

注意双引号并返回到

检查日志文件log/development.log,查看在参数中传递的值

<%= link_to 'Back', "/url_handler?url=#{@return_to}&index=0" %>