Ruby on rails 在Haml、Rails中呈现数据属性时出现问题
我一直在尝试将以下内容从html.erb转换为html.haml,但并没有100%正确地呈现。具体来说,我想知道如何在Haml中正确地编写脚本标记中的代码 html.erb:Ruby on rails 在Haml、Rails中呈现数据属性时出现问题,ruby-on-rails,haml,erb,Ruby On Rails,Haml,Erb,我一直在尝试将以下内容从html.erb转换为html.haml,但并没有100%正确地呈现。具体来说,我想知道如何在Haml中正确地编写脚本标记中的代码 html.erb: <%= form_tag charges_path do %> <h4>So what comes with being a Blocipedia premium member? </h4> <p>The ability to create your very OWN
<%= form_tag charges_path do %>
<h4>So what comes with being a Blocipedia premium member? </h4>
<p>The ability to create your very OWN private wikis of course!</p>
<script class='stripe-button' src="https://checkout.stripe.com/checkout.js" data-key="<%= @stripe_btn_data[:key] %>" data-amount=<%= @stripe_btn_data[:amount] %> data-description="<%= @stripe_btn_data[:description] %>" ></script>
<% end %>
在我试图用Haml重写代码之前,我的原始html.erb文件呈现如下
Haml之前(我的页面应呈现的方式):
然而,在尝试更改为Haml之后,我并没有100%成功地以完全相同的方式呈现页面
Haml之后(注意数据金额($15.00)和数据描述(BigMoney会员资格)没有显示)
正确呈现此页面的Haml语法是什么
更新
我正试图从我的charges_controller.rb获取数据量和描述
费用(u controller.rb):
class ChargesController < ApplicationController
def create
# Creates a Stripe Customer object, for associating with the charge
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeToken]
)
# Where the real magic happens
charge = Stripe::Charge.create(
customer: customer.id, # Note -- this is NOT the user_id in your app
amount: Amount.default,
description: "BigMoney Membership - #{current_user.email}",
currency: 'usd'
)
flash[:notice] = "Thanks for all the money, #{current_user.email}! You now have a premium Blocipedia account! Feel free to pay me again."
current_user.update_attribute(:role, "premium")
redirect_to root_path # Or wherever
# Stripe will send back CardErrors, with friendly messages when something goes wrong.
# This rescue block catches and displays those errors.
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
def new
@stripe_btn_data = {
key: "#{ Rails.configuration.stripe[:publishable_key] }",
description: "BigMoney Membership - #{current_user.name}",
amount: Amount.default
}
end
def destroy
if current_user.update_attributes(role: "standard")
flash[:notice] = "You now have a standard Blocipedia account. Feel free to upgrade back to premium at anytime!"
redirect_to root_path
else
flash[:error] = "There was an error downgrading your account. Please contact technical support."
redirect_to edit_user_registration_path
end
end
end
使用HAML实现与ERB相同的HTML输出
= form_tag charges_path do
%h4 So what comes with being a Blocipedia premium member?
%p The ability to create your very OWN private wikis of course!
%script.stripe-button{data: {key: @stripe_btn_data[:key], amount: @stripe_btn_data[:amount], description: @stripe_btn_data[:description]}, src: "https://checkout.stripe.com/checkout.js"}
我在
erb
和haml
中都没有看到BigMoney会员资格
代码,我正试图通过@stripe\u btn\u数据实例变量引用数据描述和数据金额my charges\u controller.rb文件。谢谢!这正是我要找的。
class Amount
def self.default
15_00
end
end
= form_tag charges_path do
%h4 So what comes with being a Blocipedia premium member?
%p The ability to create your very OWN private wikis of course!
%script.stripe-button{data: {key: @stripe_btn_data[:key], amount: @stripe_btn_data[:amount], description: @stripe_btn_data[:description]}, src: "https://checkout.stripe.com/checkout.js"}