Ruby on rails 如何用这种方法接吻和亲吻
我的RoR应用程序中有一个操作,它根据运行它的用户调用不同的脚本Ruby on rails 如何用这种方法接吻和亲吻,ruby-on-rails,performance,Ruby On Rails,Performance,我的RoR应用程序中有一个操作,它根据运行它的用户调用不同的脚本 def index @user = User.find(session[:user_id], :include => [ :balances, :links, :comments ]) render :file => "#{RAILS_ROOT}/app/views/user/index_#{@user.class.to_s.downcase}.html.erb" end 如何调用以呈现更优雅和简单的
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :file => "#{RAILS_ROOT}/app/views/user/index_#{@user.class.to_s.downcase}.html.erb"
end
如何调用以呈现更优雅和简单的内容?您可以将其设置为部分内容(index\u whatever.html.erb-->\u index\u whatever.html.erb),如下所示:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => "index_#{@user.class.to_s.downcase}"
end
def view
"index_#{class.to_s.downcase}"
end
另外,我要做的是在用户模型中添加一个方法,如下所示:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => "index_#{@user.class.to_s.downcase}"
end
def view
"index_#{class.to_s.downcase}"
end
因此,您的索引操作将是:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => @user.view
end
您可以将其设置为部分(index_whatever.html.erb-->u index_whatever.html.erb),其外观如下:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => "index_#{@user.class.to_s.downcase}"
end
def view
"index_#{class.to_s.downcase}"
end
另外,我要做的是在用户模型中添加一个方法,如下所示:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => "index_#{@user.class.to_s.downcase}"
end
def view
"index_#{class.to_s.downcase}"
end
因此,您的索引操作将是:
def index
@user = User.find(session[:user_id], :include => [ :balances, :links, :comments ])
render :partial => @user.view
end
尝试:
尝试:
谢谢你的回答。最后,对我来说正确的解决方案是:render:template=>“user/index_35;{@user.class.to_.s.downcase}”,谢谢您的回答。最后,对我来说正确的解决方案是:render:template=>“user/index_35;{@user.class.to_.s.downcase}”