活动管理 - 闪现消息未出现在页面上

发布于 2024-12-12 08:42:40 字数 202 浏览 0 评论 0原文

我试图在重定向到页面后显示通知,但它没有出现。

这是重定向 -

redirect_to :action => :index, :notice => "My redirect"

您可以在网址中看到该消息,但活动管理中似乎没有任何代码来显示它。

有什么想法如何在活动管理中呈现它吗?

I am trying to display a notice after redirecting to a page but it doesnt appear.

Here is the redirect -

redirect_to :action => :index, :notice => "My redirect"

You can see the message in the url but there doesnt seem to be any code inside active admin to display it.

Any ideas how to render it inside active admin ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-12-19 08:42:40

似乎有一些问题我还没有找到,但如果您在那之前正在寻找解决方法,这就是我所做的:

member_action :test do
  flash[:notice] = "This is a test notice!"
  redirect_to :action => :index
end

我看到的问题是当您输入 :noticeredirect_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 on github 发布了对该特定拉取请求的评论,希望有人可能还有另一个建议,因为我很困惑。

无论如何,也许这些解决方案之一适合您。祝你好运。

There seems to be some issue that I haven't tracked down yet, but if you are looking for a work-around until then, this is what I did:

member_action :test do
  flash[:notice] = "This is a test notice!"
  redirect_to :action => :index
end

The problem that I am seeing is that when you put :notice in the redirect_to method, the notice message is url encoded and added to the URL

member_action :test do
  redirect_to :action => :index, :notice => "This is a test notice!"
end

results in

/admin/model?notice=This+is+a+test+notice!

which is less than ideal. I noticed a change to the active_admin documentation that includes putting {} around the first parameter to redirect_to to fix this problem, however, for me, this results in an error.

member_action :test do
  redirect_to {:action => :index}, :notice => "This is a test notice!"
end

which results in

syntax error, unexpected tASSOC, expecting '}'
    redirect_to {:action => :index}, :notice => "This...

I posted a comment on that particular pull request @ active_admin on github and hopefully someone might have another suggestion, since I am stumped.

In any event, maybe one of these solutions will work for you. Good luck.

逆蝶 2024-12-19 08:42:40

Active Admin 不会呈现 Flash 消息,它认为它们是在布局中呈现的。
当您运行 active_admin:install 生成器时,它提到:

$ 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>

Active Admin doesn't render flash messages, it believes they are rendered in t layout renders them.
When you run active_admin:install generator it mentions that:

$ 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文