2011-10-27 52 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