开发者

How can I use another view if a specific parameter is given?

I have an actio开发者_如何学Cn called new:

  def new
    @bookmark = Bookmark.new

    respond_to do |format|
      format.html # new.html.erb
      format.mobile
      format.xml  { render :xml => @bookmark }
    end
  end

Now, when the param[:widget] == "true", I want to use a lay-out other than application.html.haml, and I want to show another view than new.html.haml called new_widget.html.haml.

How can I do this? Thanks.


Something like this?

def new
  @bookmark = Bookmark.new

  if params[:widget] == "true"
    render 'new_widget.html.haml', :layout => 'path/to/other/layout'
    return
  end

  respond_to do |format|
    format.html # new.html.erb
    format.mobile
    format.xml  { render :xml => @bookmark }
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜