![](/img/trans.png)
[英]Haml: syntax error, unexpected keyword_ensure, expecting end-of-input
[英]HAML - error unexpected keyword_ensure, expecting end-of-input
語法haml有什么問題? 我用了2個空格。 顯示錯誤: /home/user/myapp/bds/app/views/polls/_voting_form.html.haml:14:語法錯誤,意外的keyword_ensure,期望輸入結束
= form_tag votes_path, method: :post, remote: true, id: 'voting_form'
= hidden_field_tag 'poll[id]', @poll.id
= render partial: 'polls/poll_item', collection: @poll.poll_items, as: :item
%p
%b Итого голосов: = @poll.votes_count
- if current_user.voted_for?(@poll)
%p Вы уже голосовали!
- else
= submit_tag 'Голосовать', class: 'btn-bg'
我看到兩個錯誤:
form_tag
行上的do
。 votes_count
:要么使用字符串插值,要么在多行上寫(現在它只是將其打印為字符串) 所以最簡單的解決方案是編寫
%b Итого голосов: #{@poll.votes_count}
這是兩個錯誤:
= form_tag votes_path, method: :post, remote: true, id: 'voting_form' # <= missing do
....
%p
%b Итого голосов: = @poll.votes_count # <= no valid haml
應該
= form_tag votes_path, method: :post, remote: true, id: 'voting_form' do
....
%p
%b
Итого голосов:
= " #{@poll.votes_count}"
您可能不會將普通文本添加到需要=
的ruby代碼段中。 我不認為有一個編譯器可以解釋這個。 所以:
%b= @poll.votes_count # this works
%b Votes count: = @poll.votes_count # this does not
因此:
%b
Итого голосов:
= " #{@poll.votes_count}"
要么
%b= "Итого голосов: #{@poll.votes_count}"
是要走的路。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.