HAML和条纹在form_for中,我不断收到编译错误。有什么明显的错误吗?

我只是将我的应用程序切换到rails 3.1和ruby 1.9。我也通过他们的API整合了Stripe。也许这是造成问题? 我无法弄清楚我的生活这个表格的问题是什么。它说第一个错误在第3行与else声明(这是一个编译错误,下面的完整错误细节)。所有的缩进都是一致的,我逐行进行修复。让我知道是否应该发布更多信息,比如我的gemfile或其他东西。HAML和条纹在form_for中,我不断收到编译错误。有什么明显的错误吗?

这里是有问题的形式:

=if 

%h1 Sign up

=else

%h1 Edit

=form_for(@user) do |f|

=render "shared/error_messages", :target => @user

=f.hidden_field :stripe_card_token

%dl

=if signed_in?

%dt.field=f.label :avatar

%dd.field=f.file_field :avatar

%dt.field=f.label :name

%dd.field=f.text_field :name

%dt.field=f.label :email

%dd.field=f.text_field :email

=if @user.new_record?

%dt.field=f.label :password

%dd.field=f.password_field :password

=if @user.stripe_card_token.present?

%p Credit card has been provided.

=else

%div.field

=label_tag :card_number, "Credit Card Number"

=text_field_tag :card_number, nil, name:nil

%div.field

=label_tag :card_code, "Security Code on Card (CVV)"

=text_field_tag :card_code, nil, name:nil

%div.field

=label_tag :card_month, "Card Expiration"

=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#stripe_error

%noscript JavaScript is not enabled and is required for this form. First enable it in your web browser settings.

.actions

=f.submit((defined?(editing) ? "Update" : "Sign Up"))

以下是错误:

compile error 

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:3: syntax error, unexpected kELSE

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:23: syntax error, unexpected kELSE

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:25: syntax error, unexpected tSYMBEG, expecting kDO or '{' or '('

...d_tag :card_number, nil, name:nil

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:27: syntax error, unexpected tSYMBEG, expecting kDO or '{' or '('

...eld_tag :card_code, nil, name:nil

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: odd number list for Hash

...month nil, {add_month_numbers: true}, {name: nil, id: "card_...

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: syntax error, unexpected ':', expecting '}'

...month nil, {add_month_numbers: true}, {name: nil, id: "card_...

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: odd number list for Hash

...d_month_numbers: true}, {name: nil, id: "card_month"}

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: Can't assign to nil

...th_numbers: true}, {name: nil, id: "card_month"}

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: syntax error, unexpected ':', expecting '='

...umbers: true}, {name: nil, id: "card_month"}

^

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:30: syntax error, unexpected '}', expecting ')'

/Users/brianjoseff/rails_projects/groupie/app/views/users/_form.html.haml:37: syntax error, unexpected kENSURE, expecting $end

...Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer.u...

^

感谢所有

更新1 ...新的形式,而不JavaScript数组符号:

=if 

%h1 Sign up

=else

%h1 Edit

=form_for(@user) do |f|

=render "shared/error_messages", :target => @user

=f.hidden_field :stripe_card_token

%dl

=if signed_in?

%dt.field=f.label :avatar

%dd.field=f.file_field :avatar

%dt.field=f.label :name

%dd.field=f.text_field :name

%dt.field=f.label :email

%dd.field=f.text_field :email

=if @user.new_record?

%dt.field=f.label :password

%dd.field=f.password_field :password

=if @user.stripe_card_token.present?

%p Credit card has been provided.

=else

%div.field

=label_tag :card_number, "Credit Card Number"

=text_field_tag :card_number, :name => nil

%div.field

=label_tag :card_code, "Security Code on Card (CVV)"

=text_field_tag :card_code, :name => nil

%div.field

=label_tag :card_month, "Card Expiration"

=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#stripe_error

%noscript JavaScript is not enabled and is required for this form. First enable it in your web browser settings.

.actions

=f.submit((defined?(editing) ? "Update" : "Sign Up"))

回答:

=语句

您使用Javascript数组表示法中HAML。 HAML使用Ruby来评估=(表达):

因此,这是错误的:

= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} 

应该是:

= select_month nil, { :add_month_numbers => true}, { :name => nil, id => "card_month" } 

Else语句

的代码行不产生输出,所以使用 - 而不是=

- if 

%h1 Sign up

- else

%h1 Edit

以上是 HAML和条纹在form_for中,我不断收到编译错误。有什么明显的错误吗? 的全部内容, 来源链接: utcz.com/qa/258868.html

回到顶部