Home  >  Q&A  >  body text

ruby - rails redirect_to 如何携带返回参数

新手。
用脚手架生成的代码,notice可以在前端显示。

redirect_to users_url, notice: 'Succeed.'
<p id="notice"><%= notice %></p>

但是我添加了一个message,就失败了

redirect_to users_url, notice: 'Succeed.', message: 'test'
<p id="notice"><%= notice %></p>
<h1><%= params[:message] %></h1> #不显示
<h1><%= message %></h1> #报错不存在message
PHP中文网PHP中文网2708 days ago683

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-25 09:04:06

    notice: 'Succeed.' is the parameter of redirect_to. The parameters in params are passed by url. users_url is used to generate url, so your writing method should be
    redirect_to users_url(message: 'test'), notice: 'Succeed.'

    reply
    0
  • Cancelreply