Deny partial controller control with Ruby On Rails

Im using Rails 3 in my project.

In the controller> articles In sight> index.html.erb

<% if @articles.blank? %> <%= render :partial => "blank" %> 

I don’t want to write requests in views for verification (if it is empty or to do it) How can I pass an empty partial slider (if the set of requests is empty) inside the controller?

Thanks.

+8
ruby-on-rails ruby-on-rails-3
source share
3 answers

You can also make a switch in the controller.

 def index @articles = Article.all render "index_without_articles" if @article.nil? end 
+7
source share

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

+7
source share

this may be a workaround, but it's a pretty simple solution

 <%= render :partial => "blank_#{@articles.blank?}" %> 

and have two elementary elements called _blank_true.html.erb and _blank_false.html.erb

0
source share

Source: https://habr.com/ru/post/650942/


All Articles