我想在重定向后将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不抛出,为什么?
发布于 2012-12-01 21:13:03
只允许使用redirect_to设置:notice和:alert。
如果您想要更多,可以对redirect_to使用:flash => { :notice_small => '....' }选项,或者在redirect_to之前显式地设置flash[:notice_small]。
发布于 2012-12-01 20:52:47
据我所知,重定向看起来应该可以工作。但是,要使其在视图中可用,您要重定向到的操作必须采用params["notice_small"]并将其放入实例变量中。就像这样
@notice_small = params["notice_small"]在行动中,那么你可以这样做
<% if defined? @notice_small %>
<p id="small_notice" class="small_notice"><%= @notice_small %></p>
<% end %>https://stackoverflow.com/questions/13659541
复制相似问题