Tag: 语法错误

在rails中创建新对象时出错

每当我尝试为模型创建对象时,我都会在rails中收到此错误。 我正在使用Windows 7 C:\Ruby\joker\chapter3>ruby script/console Loading development environment (Rails 2.3.8) >> mycb = ComicBook.new SyntaxError: C:/Ruby/joker/chapter3/app/models/comic_book.rb:19: syntax error, u nexpected $end, expecting kEND from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_without_new_constant_marking’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:521:in `new_constants_in’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:379:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:259:in `require_or_load’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:425:in `load_missing_constant’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:80:in `const_missing’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:92:in `const_missing’ […]

如果每个条件都做Rails

嗨我需要打印出那些活跃的候选人== 0这里是我在视图中的代码。 我可以打印,如果活动是是或否..但在每个做循环我只想打印活跃的候选人。 那么我怎样才能将条件添加到我的每个循环中,谢谢。 我试过这个 我的所有想法都没有运气语法错误:P

为什么Ruby中有时需要括号?

我最近在查看Rails文档中的一些Ruby代码时遇到了一个奇怪的问题。 Ruby允许您传递像这些示例的参数: redirect_to post_url(@post), alert: “Watch it, mister!” redirect_to({ action: ‘atom’ }, alert: “Something serious happened”) 但那第二个案子对我来说很奇怪。 看起来你应该能够像这样传递它: redirect_to { action: ‘atom’ }, alert: “Something serious happened” 无论有没有括号,它都有相同的含义。 但相反,你得到: syntax error, unexpected ‘:’, expecting ‘}’ action后提到结肠。 我不确定它为什么会在那里,以及为什么使用括号会改变它。

字符串连接错误

我遇到了语法错误。 我接受这是一个语法错误,但我有点好奇为什么它是一个语法错误。 这完全符合您的预期: (0..9).each { |n| puts n.to_s + “^2 = ” + (n**2).to_s } 这会引发错误: (0..9).each { |n| puts n.to_s +”^2 = “+ (n**2).to_s } 错误: NoMethodError: undefined method ‘+@’ for “^2 = “:String 奇怪的是,我可以在任何地方移动第二个加号,Ruby似乎没有任何问题,但如果第一个碰巧触及双引号,我会收到语法错误。 为什么会发生这种情况呢?

意外的keyword_end,期待$ end(SyntaxError)

嘿我是ruby on rails的新手,我正在尝试从这个博客运行一个简单的程序,并面临很多问题错误。 http://goodbadtech.com/2009/05/13/ruby-on-rails-import-csv-data-into-database/无法找出解决方案。 这是错误日志。 /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load’: /home/jeevan/csv/config/routes.rb:64: syntax error, unexpected keyword_end, expecting $end (SyntaxError) from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `block in load’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `block in load_dependency’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `block in load_paths’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `each’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `load_paths’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:13:in `reload!’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:7:in `block in initialize’ from /home/jeevan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb:32:in […]

Rails 3.2 Postgres保存错误“ActiveRecord :: StatementInvalid:PG ::错误:错误:位置5’T’附近的语法错误”

当我尝试将特定类保存到数据库时,我的应用程序已经开始抛出错误。 我不确定是什么导致这种情况开始发生 – 过去几天我一直有各种各样的数据库问题…. 在任何情况下,我的模型似乎工作正常(它正确计算所有before_save值),但然后它尝试保存到数据库并爆炸。 SQL (0.8ms) INSERT INTO “portfolios” (“correlation_matrix”, “created_at”, “data”, “mean_return”, “std_dev”, “updated_at”, “weights”) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING “id” [[“correlation_matrix”, “— \n- – 1.0\n – -0.4873114574375062\n- – -0.4873114574375062\n – 1.0\n”], [“created_at”, Sat, 16 Jun 2012 15:12:35 MDT -06:00], [“data”, {“TSX”=>0.5, “VUSTX”=>0.5}], [“mean_return”, #], [“std_dev”, #], [“updated_at”, Sat, […]

Ruby中的哈希语法

根据The Well Grounded Rubyist : Ruby允许在哈希键位置使用特殊forms的符号表示,在符号之后使用冒号而不是之前的冒号并删除哈希分隔符箭头。 换句话说,这个: hash = { :name => “David”, :age => 49 } 也可以像这样写: hash = { name: David, age: 49 } 我在ruby 1.8.7和1.9.2中尝试了前面的代码 – 它无法正常工作。 我究竟做错了什么?

意外的keyword_end错误,但语法似乎很好

此函数应该从逗号分隔值文件中提取名称,并将它们放入数组中。 def xprt_csv_to_ary(csv_file) namecatcher_regex = “/^[\.{1}]([AZ]+)\.{3}/” # Matches up to char before next name current_word = 0 names_array = [] while current_word < 5000 if current_word == 0 name = csv_file.readline.match(namecatched_regex) else name = csv_file.past_match.match(namecatcher_regex) end names_array[current_word] = name current_word ++ end return names_array end 我收到以下错误: syntax error, unexpected keyword_end 我很乐意被提到一个解决我的问题的现有问题,就是让别人直接回答我。

ruby中的函数无效

为什么这个function无效? def request(method=’get’,resource, meta={}, strip=true) end 未经预料的’)’期待keyword_end 谢谢!