rails passing "each" argument in a view to a controller -
i trying pass arguments "each" loop in view controller. have list of contracts. 'contract' model has 'signed' attribute either nil or include datetime if contract signed. want list contracts in view , either render static partial if contract signed or render link sign contract if not signed. started rendering list of contracts in view along method:
<%@contract.each |contract| %> <%= @contract.reference %> <%= show_either_static_if_signed_or_link_if_not_signed %>
in helpers, defined dry-run method basic code try first contract
def show_either_static_if_signed_or_link_if_not_signed @contract = contract.find(1) if @contrat.signed.nil? render 'contracts/static_template' else render'contracts/template_with_a_link_to_sign_the_contract' end
this works fine first contract. want deploy code each contract in "each" loop of template. tried
def show_either_static_if_signed_or_link_if_not_signed(contract) if contrat.signed.nil? render 'contracts/static_template' else render'contracts/template_with_a_link_to_sign_the_contract' end
but 'i wrong number of arguments (0 1)' because fail 'contract' argument template controller. provide me appropriate syntax pass argument "each" loop of view helper method? additional suggestions approach matter welcome. thanks.
your helper method show_either_static_if_signed_or_link_if_not_signed
expecting 1 argument, however, not passing argument while calling view.
update view pass required argument follow:
<% @contract.each |contract| %> <%= contract.reference %> <%= show_either_static_if_signed_or_link_if_not_signed(contract) %> ... ... <% end %>
Comments
Post a Comment