我试图在重定向到页面后显示通知,但它没有出现。
这是重定向 -
redirect_to :action => :index, :notice => "My redirect"
您可以在 url 中看到该消息,但活动管理员中似乎没有任何代码可以显示它。
任何想法如何在活动管理员中呈现它?
我试图在重定向到页面后显示通知,但它没有出现。
这是重定向 -
redirect_to :action => :index, :notice => "My redirect"
您可以在 url 中看到该消息,但活动管理员中似乎没有任何代码可以显示它。
任何想法如何在活动管理员中呈现它?
似乎有一些问题我还没有找到,但是如果你在那之前一直在寻找解决方法,这就是我所做的:
member_action :test do
flash[:notice] = "This is a test notice!"
redirect_to :action => :index
end
我看到的问题是,当您:notice
输入redirect_to
方法时,通知消息是 url 编码并添加到 URL
member_action :test do
redirect_to :action => :index, :notice => "This is a test notice!"
end
结果是
/admin/model?notice=This+is+a+test+notice!
这不太理想。我注意到对 active_admin 文档的更改,其中包括放置{}
第一个参数来redirect_to
解决此问题,但是,对我来说,这会导致错误。
member_action :test do
redirect_to {:action => :index}, :notice => "This is a test notice!"
end
这导致
syntax error, unexpected tASSOC, expecting '}'
redirect_to {:action => :index}, :notice => "This...
我在 github上对那个特定的拉取请求 @active_admin 发表了评论,希望有人可能有另一个建议,因为我很难过。
无论如何,也许其中一种解决方案对您有用。祝你好运。
Active Admin 不呈现 flash 消息,它认为它们是在 t 布局中呈现的。当您运行 active_admin:install generator 它提到:
$ rails g active_admin:install
...
Some setup you must do manually if you haven't yet:
...
3. Ensure you have flash messages in app/views/layouts/application.html.erb. For example:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>