我遵循Ryan Bates' RailsCast #288 "Billing with Stripe",当我修改我的表单以包括信用卡信息时,我得到以下错误:
compile error
/Programs/domainster/app/views/domains/_form.html.erb:23: syntax error, unexpected ':', expecting ')'
...d_tag :card_number, nil, name: nil );@output_buffer.safe_con...
我根据RailsCast检查了语法,代码是相同的。我甚至更新了我的GemFile以确保我有最新的Rails运行。
这是我的表格:
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="field">
<%= label_tag :card_number, "Credit Card Number" %><br />
<%= text_field_tag :card_number, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :cvv, "Security Code on Card (CVV)" %><br />
<%= text_field_tag :cvv, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_month, "Card Expiration" %><br />
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
</div>
<div class="actions">
<%= f.submit "Generate"%>
</div>
我一步一步地跟随RailsCast,我不知道为什么我得到这个错误。什么好主意吗?
问题是Ryan使用Ruby 1.9.2语法来处理哈希
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
需要写成
<%= select_year nil, {:start_year =>日期。年份,:end_year =>Date.today。年+ 15},{:name => nil,: id =>"card_year"}%>
在1.8.7上运行。检查其他行,看看是否还有其他需要修改的地方。