开发者

Render partial in controller using Ruby On Rails

开发者 https://www.devze.com 2023-02-04 04:27 出处:网络
Im using Rails 3 in my project. In controller > articles In view > index.html.erb <% if @articles.blank? %>

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"

0

精彩评论

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