2011-10-27 53 views
15

上的Flash消息我试图在重定向到页面后显示通知,但它不出现。活动管理员 - 未出现在第

这里是重定向 -

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

你可以看到消息中的网址但似乎没有被激活管理员显示它内部的任何代码。

任何想法如何将其呈现在活动管理员内?

+0

你有一个: <%= flash [:notice]%> 在你看来? – Cygnusx1

+0

活动管理员生成的意见,所以我不知道。 – Alex

回答

22

似乎有一些问题,我没有跟踪下来了,但如果你正在寻找一个变通此之前,这是什么我所做的:

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

我张贴在那个特定的拉动请求@active_admin on github评论,希望有人可能有另一项建议,因为我难倒。

无论如何,其中一种解决方案可能适合您。祝你好运。

+0

flash [:notice] work around为我工作。我花了一个小时搞这个,直到找到答案。 – jevy

+4

您在使用ruby语法时遇到问题。尝试添加括号:'redirect_to({action::index},注意:'无论')' – chrpes

+0

在成员动作中使用'flash [:notice]'对我来说无法正常工作(不会消失),但@chrpes提供的上述解决方案的确如此。 – SexxLuthor

-4

Active Admin不呈现Flash消息,它认为它们呈现在t layout中呈现它们。 当您运行active_admin:安装发电机也提到:

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

我已经将它们添加到了我的布局中,但我想在活动管理员所创建的视图上显示一条Flash消息 – Alex

+1

您上面引用的输出来自active_admin安装的设计安装部分。换句话说,devise建议您更新布局以包含通知/警报字段。这与active_admin如何显示其通知/警报消息无关。 – sorens