Render partial in controller using Ruby On Rails
Im using Rails 3 in my project.
In controller > articles In view > index.html.erb
<% if @articles.blank? %>
<%= render :partial => "blank" %>
I dont want to write querysets i开发者_运维知识库n views for checkin (if empty do this or do this) How can I pass blank slate partial (if queryset is empty) inside controller ?
Thanks.
You can also make the switch in the controller.
def index
@articles = Article.all
render "index_without_articles" if @article.nil?
end
I believe you want render_to_string
. See this blog post for more info on rendering in Rails 3.
maybe it's a workaround but it's quite an easy solution
<%= render :partial => "blank_#{@articles.blank?}" %>
and have two partials called "_blank_true.html.erb" and "_blank_false.html.erb"
精彩评论