2012-12-18 205 views
0

我经历了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(' 
          ^

我想:应该有class.can任何一个后请建议如何纠正这个错误

+1

Ruby解释器的版本号是多少? –

+0

ruby​​翻译版本是1.8.7 –

+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时,无论哪种写法都是正确的。