Rails generate model syntax error - ruby-on-rails

I'm trying to generate a model from the command line. Here is my command:
rails generate model User first_name:string last_name:string email_address:string age:integer
And it keeps giving me this error:
SyntaxError: (irb):2: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
User first_name:str last_name:**str** email_address:str age:int
(irb):2: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
name:str email_address:str age:**integer**
I'm lost. I learned this yesterday and the syntax is exactly the same as before when it worked fine.
Thanks
Edit: StackOverflow wouldnt let me post this unless I formatted that error as code FYI

You should put this command in your system console, not Rails console.

Related

syntax error near unexpected token ( in Lua

I'm playing with lua, using the following link: https://www.lua.org/pil/8.html and got confused about this syntax error.
So, the file foo.lua is as the following:
function foo (x)
print(x)
end
Then,
~$ f = loadfile("foo.lua")
bash: syntax error near unexpected token `('
Any comments are greatly appreciated.

Rails: mongodb error when using $lt

this code return an error
db[:zips].find(city: {$lt: 'd'}).limit(2).to_a.each{|r| pp r}
syntax error, unexpected '}', expecting end-of-input
However, this code works well
db[:zips].find(city: {:$lt=> 'd'}).limit(2).to_a.each{|r| pp r}
Why can not use :$lt like the first one?
You can't use the JSON-like {key: value} syntax in this case , because the key starts with $. Either use the older hash syntax or, since ruby 2.2,
{'$lt': 'd'}
I couldn't find a reference for when quoting is required (emojis are OK for example) - I suspect you would have to delve into the ruby source for this.

Syntax error, unexpected tSTRING_BEG ROR

Below is my code:
gem_package 'cucumber' do
clear_sources true
source https://chefrubyaehq.kdc.example.com/
gem_binary '/opt/chef/embedded/bin/gem'
action :install
end
And I am getting the following error:
FATAL: zng937-test/recipes/default.rb:43: unknown regexp options - chfrbyahq
FATAL: zng937-test/recipes/default.rb:44: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
FATAL: gem_binary '/opt/chef/embedded/bin/gem'
Does anyone have any idea why I would be getting this?
You need to put the source (https://chefrubyaehq.kdc.capitalone.com/) inside quotes to make it a string. Either single or double quotes is fine for this case.
Just as the message says.
Your regex //chefrubyaehq is invalid. Ruby regex only has i, o, x, m options.
You forgot to put a period after your regex /\n gem_binary '/ before the method opt.
And when you fix those, you will still encounter more errors.

how to use getText function in cucumber with ruby-on-rails

I am trying to use getText function ,but its giving error.
assert_equal "Comment List", find(:xpath,'//div[#id='pageContainer']/div[2]/h2').getText()
and error is -
C:/Workspace/cucumber-project/features/step_definitions/comment_steps.rb:135: sy ntax error, unexpected ')', expecting kEND ...d='pageContainer']/div[2]/h2').text ^ (SyntaxError)
Can anybody help me in that, i just want to compare the text by finding through xpath with the expected text
This isn't a Cucumber issue, it's a Ruby syntax error. Your quotes are the problem, you need to do either:
"//div[#id='pageContainer']/div[2]/h2"
or
'//div[#id="pageContainer"]/div[2]/h2'

Ruby on Rails Error in rake db:migrate syntax error, unexpected $end, expecting '}'

I get this error when I run rake db:migrate
*db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: invalid multibyte char (US-ASCII)
db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: invalid multibyte char (US-ASCII)
db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: syntax error, unexpected $end, expecting '}'
...celeration' => [{:name =>'m/s²', :si => true, :conversion_f...*
Then I checked it using *$ ruby -wc db/migrate/004_add_data_to_measurement_type_and_measurement_unit.rb* and got the same error.
I was sure that I have all the right gems in place, so I tested by removing the superscript in the line, making it :name =>'m/s' from :name =>'m/s²'. This removed the error.
But problem is that I need the superscript and do not know how previous developer managed to run the db:migrate on this. Have you seen something similar?
Thanks
The problem is that the superscript is not ASCII.
The previous developer may have set something so that UTF-8 was always assumed, but you should be able to do it for this script specifically by adding the magic comment
# coding: utf-8
near the top of the script.

Resources