8

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 in views for checkin (if empty do this or do this) How can I pass blank slate partial (if queryset is empty) inside controller ?

Thanks.

1
  • Why do you not want to check whether @articles is blank in the view? Commented Jan 11, 2011 at 19:04

3 Answers 3

7

You can also make the switch in the controller.

def index
  @articles = Article.all
  render "index_without_articles" if @article.nil?
end
Sign up to request clarification or add additional context in comments.

Comments

7

I believe you want render_to_string. See this blog post for more info on rendering in Rails 3.

Comments

0

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.