Domanda

I'm trying to render different partials into my index view from the controller, depending on the params I receive. I have a simple unless-else condition inside my controller that checks the params

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

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

Now, how can I show that partials inside my index view? At the moment I can just visualize the partial alone as a single view, but not inside the requested view.

È stato utile?

Soluzione

The better way would be to call the partials from index.html.erb

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

so your def index would look like this

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

I did not understand what you are trying to do but partial which are related to controller/actions should not be in layout unless they are serving some layout.

Altri suggerimenti

If you're trying to render a layout (and not actual view information) try using render layout

def index
  if params[:check].nil?
    render layout: "not_check"
  else
    render layout: "check"
  end
end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top