2011-05-20 90 views
1
SyntaxError in Videos#show 

Showing /rubyprograms/dreamstill/app/views/videos/show.html.erb where line #54 raised: 

compile error 
/Library/Ruby/Gems/1.8/gems/activemodel-3.0.4/lib/active_model/attribute_methods.rb:272: syntax error, unexpected ')' 
/Library/Ruby/Gems/1.8/gems/activemodel-3.0.4/lib/active_model/attribute_methods.rb:273: syntax error, unexpected '?', expecting $end 
Extracted source (around line #54): 

51:   <%= link_to "Show Song", '#', :id => 'video_show_link', :class => 'edit' %> 
52:  
53:   <div id="showable_video_div"> 
54:    <%= form_for [@video, @video.showable_videos.new ], :url => showable_videos_path, :remote => true do |f| %> 
55:     <%= f.hidden_field :video_id, :value => @video.id, :id => "video_id_field" %> 
56:     <%= f.text_field :user, :class => "showable_field" %> 
57:    <% end %> 

这是迁移到我做得对抛出的错误之前的showable_videos表:我的语法错误在哪里?

class AddUpvotedAndSeenToShowableVideos < ActiveRecord::Migration 
    def self.up 
    add_column :showable_videos, :upvoted?, :boolean 
    add_column :showable_videos, :seen?, :boolean 
    end 

    def self.down 
    remove_column :showable_videos, :seen? 
    remove_column :showable_videos, :upvoted? 
    end 
end 
+0

什么是'[@video,@ video.showable_videos.new]'应该产生? – theIV 2011-05-20 04:44:59

+1

语法错误在您的标题中。 Wheres ==> – sawa 2011-05-20 04:47:24

+0

在视频模型中:'has_many:showable_videos' – user730569 2011-05-20 04:47:41

回答

1

我只是解开上面的迁移,然后再次运行迁移,而在列名?。我不再听到语法错误。

+0

事实上,这将解决它,Rails自动提供这些方法,所以如果你自己添加它在该列上将不起作用。 – Bitterzoet 2011-05-20 07:53:06

+1

你应该接受你的回答;)你也可能会报告Rails中的一个错误(我想它也可能是文档中的一个错误)。 Rails应该返回一个错误,指出在Rails表列名称中问号是不合法的。例如,PostgreSQL允许你创建这样的列。由于Rails使用问号(“name?”代表属性“name”)定义阅读器方法,因此在基本列中使用此字符可能有问题。 – Arsen7 2011-05-20 08:08:08