开发者

How do I render the show view of Controller 'B' when I am in Controller 'A'?

I would like to render the show action of a user, from another controller vanity.

This is what my Vanity controller looks like:

class VanitiesController < ApplicationController

  def show
    if(v = Vanity.find_by_name(params[:vname]))
        redirect v.vain 
    else
      # If the vanity name can't be found, render a 404
      respond_to do |f|
        f.html { render :status => :not_found, :file => File.join(Rails.root, "public", "404.html") }
        f.xml  { head :not_found }
        f.any  { head :not_found }
      end
    end    
  end
end

As is, that does a redirect to /users/:id/. However, rather than redirecting I want to render that show action.

When I just do render v.vain I get this message:

Template is missing

Missing partial users/user with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html], :locale=>[:en, :en]}. Searched in: * "/app/views"

I also tried render :controller => :users, :action => :show and that simply rendered th开发者_开发知识库e :show action for my vanities controller.


render "/controller/action" 

does the trick


use this

 render :template => "b/show"


you can also use

redirect_to :controller => '', :action =>''

with parameters: redirect_to :controller => '', :action =>'', :parameter => @variable

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜