在Rails应用程序中编译时间错误

时间:2012-12-18 10:01:26

标签: ruby-on-rails ruby-on-rails-3.2

我正在浏览railstutorial.org书并在代码中获得编译时错误

<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>
<%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

我的错误是

compile error
/home/ritesh/projects/sample/app/views/static_pages/home.html.erb:8: syntax error, unexpected ':'
...to "Sign up now!", '#', class: "btn btn-large btn-primary" )...
                              ^
/home/ritesh/projects/sample/app/views/static_pages/home.html.erb:10: syntax error, unexpected ':', expecting ')'
...to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails...
                              ^
/home/ritesh/projects/sample/app/views/static_pages/home.html.erb:10: syntax error, unexpected ')', expecting kEND
...), 'http://rubyonrails.org/' );@output_buffer.safe_concat('
                              ^

我认为:课后应该在那里。任何人都请建议如何纠正这个错误

1 个答案:

答案 0 :(得分:0)

尝试使用:class =>语法代替class:

例如,而不是:

<%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %>

<%= link_to "Sign up now!", '#', :class => "btn btn-large btn-primary" %>

我非常怀疑你使用的是不支持语法的Ruby版本。在这种情况下,请尝试将Ruby更新为1.9.x。

修改

由于您的Ruby版本是1.8.7,因此在Ruby 1.9中首次引入语法时会出现编译错误。安装Ruby 1.9时,编写任何一种方法都是正确的。