Volt Framework模型的类型限制会引发错误

时间:2015-08-22 19:42:44

标签: voltrb

我想为Volt模型设置类型限制,如此

class EventItemBlock < Volt::Model :name, String :items, Volt::ArrayModel end

当我保存文件时,Volt会在幕后抛出错误但不会崩溃。相关的行是前七(7),表示逗号是语法错误。

在Volt Framework文档中,逗号记录为正确的语法(http://docs.voltframework.com/en/docs/models.html)。删除逗号不能解决错误 - 只删除类型限制。

[ERROR] #<SyntaxError: /home/jg/ModelTest/app/main/models/event_item_block.rb:2: syntax error, unexpected ',', expecting keyword_end :name, String ^ /home/jg/ModelTest/app/main/models/event_item_block.rb:3: syntax error, unexpected ',', expecting keyword_end :items, Volt::ArrayModel ^> /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:67:in `require' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:67:in `block (2 levels) in require_in_components' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:65:in `each' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:65:in `block in require_in_components' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:31:in `block in app_folders' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:30:in `each' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:30:in `app_folders' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/rack/component_paths.rb:61:in `require_in_components' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/volt/server_setup/app.rb:16:in `setup_paths' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/volt/app.rb:74:in `initialize' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/boot.rb:21:in `new' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/boot.rb:21:in `boot' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server.rb:44:in `boot_volt' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/forking_server.rb:73:in `start_child' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/forking_server.rb:229:in `block in reload' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/utils/read_write_lock.rb:65:in `with_write_lock' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/forking_server.rb:227:in `reload' /home/jg/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/volt-0.9.4/lib/volt/server/forking_server.rb:239:in `block (2 levels) in start_change_listener'

1 个答案:

答案 0 :(得分:0)

好的,这里有两件事。 1)你的语法错了。你需要这样做:

field :something, SomeClass

其次,您目前无法限制为Volt :: ArrayModel(但是,在todo列表中)