Reputation: 495
I have this code that creates a view for the donation process:
<h2 class="mbs">New Donation</h2>
<br>
<%= form_tag confirm_payment_path, id: "checkout-form" do %>
<% if current_user and !current_user.has_payment_info? %>
<%= render 'customer_form' unless @anonymous_user %>
<% end %>
<br>
<p>Please enter your donation details (this is a donation and will not be applied towards your account):</p>
<div id="payment-form"></div>
<div id='coinbase-container-id'></div>
<input type="text" name="amount" placeholder="Enter amount">
<input type="submit" class="btn btn-primary" value="Donate">
<% end %>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
var clientToken = "<%= @client_token %>";
braintree.setup(clientToken, "dropin", {
container: "payment-form",
form: "checkout-form",
coinbase: { container: "coinbase-container-id" }
}
);
</script>
I have tried this to convert it to .haml, but is not working (I think that is caused by improper indentation):
%h2.mbs New Donation
%br
= form_tag confirm_payment_path, id: "checkout-form" do
- if current_user and !current_user.has_payment_info?
= render 'customer_form' unless @anonymous_user
%br
%p Please enter your donation details (this is a donation and will not be applied towards your account):
#payment-form
#coinbase-container-id
%input{:name => "amount", :placeholder => "Enter amount", :type => "text"}
%input.btn.btn-primary{:type => "submit", :value => "Donate"}
%script{:src => "https://js.braintreegateway.com/v2/braintree.js"}
:javascript
var clientToken = " @client_token ";
braintree.setup(clientToken, "dropin", {
container: "payment-form",
form: "checkout-form",
coinbase: { container: "coinbase-container-id" }
}
);
Why is it wrong? I'm really new to .haml
Upvotes: 0
Views: 47
Reputation: 18833
The JavaScript code you have after the :javascript
declaration needs to be indented, or HAML won't put it inside the <script>
tags it generates. See the Filters documentation.
:javascript
var clientToken = " @client_token ";
braintree.setup(clientToken, "dropin", {
container: "payment-form",
form: "checkout-form",
coinbase: { container: "coinbase-container-id" }
});
You also appear to have an extra <% end %>
in your ERB source, but HAML is ignoring it.
Upvotes: 1