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.
Ruby on Rails Views Partials Partial templates (partials) are a way of breaking the rendering process into more manageable chunks. Partials allow you to extract pieces of code from your templates to separate files and also reuse them throughout your templates.
From the controller's point of view, there are three ways to create an HTTP response: Call render to create a full response to send back to the browser. Call redirect_to to send an HTTP redirect status code to the browser. Call head to create a response consisting solely of HTTP headers to send back to the browser.
A partial allows you to separate layout code out into a file which will be reused throughout the layout and/or multiple other layouts. For example, you might have a login form that you want to display on 10 different pages on your site.
You can also make the switch in the controller.
def index
@articles = Article.all
render "index_without_articles" if @article.nil?
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With