I have a ruby app that runs on heroku. I am trying to alter the input of one column in my database. I have looked around the net and stack and found that others have had luck using this line of code...
user.find(8338).update_attributes(:sport=>"men's swimming")
However when I try this I get an error stating...
irb(main):005:0> User.find(8338).update_attributes(:sport=>”men’s
swimming”)
SyntaxError: (irb):5: syntax error, unexpected tIDENTIFIER, expecting
keyword_do or '{' or '('
:sport=>”men’s swimming”)
^
from /app/vendor/bundle/ruby/2.4.0/gems/railties-
5.0.7/lib/rails/commands/console.rb:65:in `start'
from /app/vendor/bundle/ruby/2.4.0/gems/railties-
5.0.7/lib/rails/commands/console_helper.rb:9:in `start'
from /app/vendor/bundle/ruby/2.4.0/gems/railties-
5.0.7/lib/rails/commands/commands_tasks.rb:78:in `console'
from /app/vendor/bundle/ruby/2.4.0/gems/railties-
5.0.7/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /app/vendor/bundle/ruby/2.4.0/gems/railties-
5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
I have tried many alterations of the above code and get the same error. Can anyone help with this? What am I doing wrong?
User.find(8338).update_attributes(:sport=>”men’s
swimming”)
Those double quotes look suspicious. You should be using the normal " and not whatever it is you typed in there.
Related
I have an issue on Elastic Beanstalk deployment which is:
YAML syntax error occurred while parsing /var/app/ondeck/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1 /var/app/ondeck/config/environment.rb:5:in `<top (required)>' /opt/rubies/ruby-2.4.2/bin/bundle:23:in `load' /opt/rubies/ruby-2.4.2/bin/bundle:23:in `<main>'
Caused by: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1 /var/app/ondeck/config/environment.rb:5:in `<top (required)>' /opt/rubies/ruby-2.4.2/bin/bundle:23:in `load' /opt/rubies/ruby-2.4.2/bin/bundle:23:in `<main>' Tasks: TOP => environment (See full trace by running task with --trace).
As what I have read, this is because YAML forbids using tabs, instead it uses spaces.
The problem is that I manually checked every YAML file for tabs, and never found one. I think I missed something so my question is: is there any script that can go through my entire source code replacing tabs with 2 spaces in every YAML file?
It’s ruby after all: it’s easier and faster to write the script rather than ask questions on SO and google for it.
Dir['*/**/*.yml'].each do |f|
File.write(f, File.read(f).gsub(/\t/, ' '))
end
I am using watir-webdriver gem to run over a website.
I tried to click a button to load more content in a webpage, for that I used the following code:
b = Watir::Browser.new
b.goto "https://www.example.com/"
b.button(:class => "ga_Finder_Load_More").click
This code is running fine in linux(ubuntu) and I can load the data in the webpage by clicking the button. But when I run the same code in window 10 I am getting the following error,
C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:508:in `assert_exists' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:114:in `click' from leafly_v1.3.rb:70:in `block (2 levels) in <main>' from leafly_v1.3.rb:67:in `each' from leafly_v1.3.rb:67:in `block in <main>' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4-x86-mingw32/lib/nokogiri/xml/node_set.rb:187:in `block in each' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4-x86-mingw32/lib/nokogiri/xml/node_set.rb:186:in `upto' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4-x86-mingw32/lib/nokogiri/xml/node_set.rb:186:in `each' from leafly_v1.3.rb:62:in `<main>' C:\Ruby200>
Ruby version - 2.0.0
watir-webdriver - 0.9.1
Can anyone please help me to fix this or can any one suggest me alternate method to click a button.
Thanks.
It often happens between different operating systems and browsers that pages will load with slightly different timing. Try:
b.button(:class => "ga_Finder_Load_More").when_present.click
I'm trying to set up Liquid gem so that it doesn't raise exceptions on syntax errors. According to the Liquid gem Readme page, you can set different error modes and, if lax is set, it should accept "almost anything" and wouldn't raise any exception. Even if I set that mode, an exception is raised, for instance:
1.9.3-p551 :041 > Liquid::Template.error_mode = :lax
=> :lax
1.9.3-p551 :042 > Liquid::Template.error_mode
=> :lax
1.9.3-p551 :043 > Liquid::Template.parse("Thank you for your purchase at {{shop_name}")
Liquid::SyntaxError: Liquid syntax error: Variable '{{shop_name}' was not properly terminated with regexp: /\}\}/
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/block.rb:104:in `create_variable'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/block.rb:44:in `parse'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/tag.rb:10:in `parse'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/document.rb:5:in `parse'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/template.rb:122:in `parse'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/liquid-3.0.6/lib/liquid/template.rb:108:in `parse'
from (irb):43
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.17/lib/rails/commands/console.rb:47:in `start'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.17/lib/rails/commands/console.rb:8:in `start'
from /Users/david/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.17/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
What am I missing?
Seems you're missing a second }.
Instead of
Liquid::Template.parse("Thank you for your purchase at {{shop_name}")
Try
Liquid::Template.parse("Thank you for your purchase at {{shop_name}}")
It's actually the expected behavior, you can't avoid Liquid raising exceptions in this kind of cases.
(Just in case somebody bumps into the same problem, I'm not closing this question)
I've got the geokit-rails gem installed with geocoder, and have loaded my configuration correctly with the right API keys and settings. I've properly constructed ActiveRecord objects that have encoded lat and lng columns with float values. Now I am trying to simply search for venues (Venue activerecord) that are within 100km of the given origin as so:
Venue.within(100, origin: Geokit::LatLng.new(-27.12,124.2141))
Yet I keep receiving the error:
TypeError: no implicit conversion of Symbol into Integer
from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/sql.rb:14:in `[]'
from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/sql.rb:14:in `full_distance'
from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/stores/active_record.rb:157:in `distance_sql'
from /usr/local/lib/ruby/gems/2.1.0/gems/geokit-rails-2.0.1/lib/geokit-rails/acts_as_mappable.rb:228:in `distance_conditions'
from /usr/local/lib/ruby/gems/2.1.0/gems/geokit-rails-2.0.1/lib/geokit-rails/acts_as_mappable.rb:108:in `within'
from (irb):46
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/console.rb:90:in `start'
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/console.rb:9:in `start'
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:69:in `console'
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Would someone help?
You could use Geokit within method with Lat&Long directly - from docs.
F.e:
:origin => [37.792,-122.393].
In your case Venue.within(100, origin: [-27.12,124.2141])
Why do you use Geokit::LatLng.new for this?
When I open up a page that's using my CSS it will work once, but won't work again until you open up the CSS and re-save it. Every other time I try to directly access my CSS, it works fine. But the other times, it doesn't work and I receive this server output:
[2010-08-01 12:49:37] ERROR NoMethodError: private method `gsub!' called for #<Class:0x7f6d0639ad80>
/usr/lib/ruby/1.8/webrick/htmlutils.rb:16:in `escape'
/usr/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
/var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:94:in `handle_file'
/var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:73:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:60:in `dispatch'
/var/www/rails-blog/vendor/rails/railties/lib/commands/servers/webrick.rb:66
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
/var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
/var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
/var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
/var/www/rails-blog/vendor/rails/railties/lib/commands/server.rb:49
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
127.0.0.1 - - [01/Aug/2010:12:49:37 BST] "GET /stylesheets/scaffold.css HTTP/1.1" 500 343
- -> /stylesheets/scaffold.css?1280662371
The code I'm using to include the stylesheet is <%= stylesheet_link_tag 'scaffold' %>. I've restarted the Ruby server but with no effect. What could be causing this problem?
This is from reading one of the official guides.
This does not happen when running Mongrel.
This is a bug in WEBrick, see http://www.ruby-forum.com/topic/206225.
On 10.06.2010 03:19, Michael Pitman (mcp) posted:
To continue using Webrick, instead of
switching to Mongrel, you can also
just edit line 15 of
lib/ruby/1.8/webrick/htmlutils.rb to
read
str = string ? string.to_s.dup : ""
The problem is that NotModified
exception is getting passed to
HTMLUtils::escape as a class, rather
than a string (originally raised in
HTTPServlet::DefaultFileHandler).
Since the only things that can really
be HTML escaped are strings, it should
be safe to always convert the input
to string.
I suspect that the potential
performance penalty may prevent a
solution like that from making it to
the standard ruby library, but it's a
simple workaround.
Alternatively, in the handle_file
method of webrick's DispatchServlet
(lib/webrick_server.rb in the rails
gem), before it calls res.set_error
with the exception, you could force
the err.message to be a string, or
even clear the message, since I think
it's discarded anyway for
NotModified.
Michael