我想在重定向后将2个字符串传递给视图。 控制器:导轨通过参数重定向后查看
def create
@rating = Rating.new(params[:rating])
respond_to do |format|
if @rating.save
format.html { redirect_to @rating, :notice => 'Got It!' ,
:notice_small => 'Your photo has been uploaded. good luck with it\'s coolness rating!' }
format.json { render :json => @rating, :status => :created, :location => @rating }
else
format.html { render :action => "new" }
format.json { render :json => @rating.errors, :status => :unprocessable_entity }
end
end
end
的观点:
<p id="notice" class="big_notice"><%= notice %></p>
<% if defined? notice_small %>
<p id="small_notice" class="small_notice"><%= notice_small %></p>
<% end %>
通知串去扔但notice_small没有,为什么?
我如何在视图中访问它? – WebQube
'flash [:notice_small]'。 – jdoe
您的'notice'只是'flash.notice'的快捷方式,它依次调用'flash [:notice]'。所以你可以通过'flash [:...]''同时访问':notice'和':notice_small'。 – jdoe