I would like to render partials into a view based on conditions. At first I have this view which renders well
<%= simple_form_for [@customer, @reading], :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :customer_id, :editable => false, :value => @customer.id %>
<%= f.input :date_of_reading, :as => :date %>
<%= render 'readings/single_phase', f: f %>
<% end %>
I now want to render partials into the view based on conditions. So i create a helper method in application.rb to do the conditional checking
module ApplicationHelper
def render_readings_conditionally
if @customer.phase_type == 'Single Phase'
render :partial => 'readings/single_phase'
else
render :partial => 'readings/three_phase'
end
end
end
And in my view, I fix the method in there
<%= simple_form_for [@customer, @reading], :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :customer_id, :editable => false, :value => @customer.id %>
<%= f.input :date_of_reading, :as => :date %>
<%= render_readings_conditionally %>
<% end %>
However, this will not work because I have not passed the block argument i had earlier on to my partials.
How can i pass it to my partials?
Just rewrite it this way :
And in your view :