The rails are partially processed by the controller

I am trying to display different particles in my index view from the controller, depending on the parameters that I get. I have a simple if-else parameter inside my controller that checks the parameters

def index unless params[:check].nil? render :partial => /layout/check else render :partial => /layout/not_check end end 

And I have _check.html.erb and not_check.html.erb files in the layout of the / folder

Now, how can I show that particles are inside my index view? At the moment, I can just imagine partial only as a single view, but not inside the requested view.

+6
source share
2 answers

It would be best to call partial elements from index.html.erb

 <% unless params[:check].nil? %> <%= render :partial => '/layout/check' %> <% else %> <%= render :partial => '/layout/not_check' %> <% end %> 

so your def index will look like this

 def index respond_to do |format| format.html end end 

I did not understand what you are trying to do, but the partial ones related to the controller / actions should not be in the layout if they do not serve any layout.

+4
source

If you are trying to display the layout (and not the actual viewing information), try using a rendering layout

 def index if params[:check].nil? render layout: "not_check" else render layout: "check" end end 
0
source

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


All Articles