Mdjon26
Mdjon26

Reputation: 2255

Having logic in a Haml file?

I have two buttons so the user can choose two options:

= button_to t('payer_contracts.new_global_payer_type'), new_payer_contract_path, {:class => 'btn pull-left', :method => 'get'}

= button_to t('payer_contracts.new_bpci_payer_type'), new_payer_contract_path, {:class => 'btn pull-left', :method => 'get'}

Both of them direct to the same file as seen here:

- content_for(:title, t('payer_contracts.page_titles.new'))

- content_for :article do
  .common-main-container
    %h1= t('payer_contracts.new_payer_contract')
    = render 'global_form'

The problem is, if the user clicks either button, it will render the global_form. I want the first button to render the global_form and the second button to render the bpci_form. Is there a way I can send an argument in the path such as:

new_payer_contract_path(payer_contract.new_bpci_payer_type)

and then in the form use some type of logic for:

if (payer_contract(new_bpci_payer_type)
  = render 'bpci_form'
else
  = render 'global_form'

Is this possible?

Upvotes: 1

Views: 240

Answers (1)

Sasidaran
Sasidaran

Reputation: 454

Yes, you can pass the value in the action

new_payer_contract_path(payer_type: payer_contract.new_bpci_payer_type)

to any one of the button, and in the view file you can get the params using

if payer_contract(params[:payer_type])
  = render 'bpci_form'
else
  = render 'global_form'

Upvotes: 0

Related Questions