Seed Data Syntax Error - ruby

I'm super new to rails and coding,
I have my seed.rb file and the first line is
Food.create! ( name: "Avocado")
When I try to rake db:seed, I get this error:
SyntaxError: /Users/meganryll/Desktop/foodninja/db/seeds.rb:8: syntax error, unexpected tLABEL, expecting ')'
Food.create! ( name: "Avocado")
Could anyone tell me what is wrong with that syntax?
Thanks

Ruby does not like spaces between the method name and the argument parentheses.
Food.create!( name: "Avocado")

Related

Ruby - end pattern with unmatched parenthesis: /

I'm getting different error based on space between after divide(/) operator. Lets consider following example.
$ ruby -e "a /100"
-e:1: unterminated string meets end of file
-e:1: syntax error, unexpected tSTRING_END, expecting tSTRING_CONTENT or tREGEXP_END or tSTRING_DBEG or tSTRING_DVAR
$ ruby -e "a / 100"
-e:1: undefined local variable or method `a' for main:Object (NameError)
The second example gives proper error message while the first one gives weird error. I did some research, but couldn't find out the reasons behind it. Is there anyway to fix this to give proper error messge?
If I try this with Ruby 2.3.1, I get this message: -e:1: unterminated regexp meets end of file Which seems valid since "/" is normally a regex marker...
And in the second line of your error message it says it is expecting a tREGEXP_END.
So, I think, everything is fine.
I tried this in the terminal and got the same regexp error:
$ ruby -e "a /100"
-e:1: unterminated regexp meets end of file
It seems like the /100 was interpreted as a regexp. The simple solution is to follow the correct ruby syntax (i.e. your second example: $ ruby -e "a / 100" ). Normally, it is recommended to add spaces around ruby operators, as suggest by the ruby style guide.

Why is "true || File.exist? 'touch'" invalid syntax?

The following is invalid:
true || File.exist? 'touch'
SyntaxError: unexpected tSTRING_BEG, expecting end-of-input
true || File.exist? 'touch'
^
However, if you remove the true ||, or use brackets around 'touch', it's valid:
File.exist? 'touch'
=> false
true || File.exist?('touch')
=> true
Why is the combination of the true || and not using brackets invalid syntax?
Doing a search for SyntaxError: unexpected tSYMBEG only got https://github.com/bbatsov/rubocop/issues/1232 , and doing a search for SyntaxError: unexpected tSTRING_BEG seemed to mainly get people who'd made some sort of typo such as RoR: syntax error, unexpected tSTRING_BEG, expecting ')' and Ruby syntax error, unexpected tSTRING_BEG, expecting ':' (SyntaxError)
This will work
true or File.exist? 'touch'
The reason is does is because || has higher precedence than or, and with || your expression simplifies to (true || File.exist?) 'touch'.
I'm not recommending you use or, but consider always using parenthesis - most Ruby guidelines (Vanilla Ruby and Rails) recommend using them at all times.
Community driven ruby style guide:
Omit parentheses around parameters for methods that are part of an internal DSL (e.g. Rake, Rails, RSpec), methods that have "keyword" status in Ruby (e.g. attr_reader, puts) and attribute access methods. Use parentheses around the arguments of all other method invocations.

error after installing magento

Parse error: syntax error, unexpected 'Sns_Avaz_Model_Observer'
(T_STRING) in
/home/ganyobiclothing/public_html/app/code/local/Sns/Avaz/Model/Observer.php
on line 1
If this is the sns-avaz-responsive-magento-theme you should check the following page: http://themeforest.net/item/sns-avaz-responsive-magento-theme/11951628/comments
Hi,
This issue only happen with some hosting/server – it compress content file
We’ve fixed this issue on v1.0.1. Please try go to file: >/app/code/local/Sns/Avaz/Model/Observer.php open it and add space after re-save.
Ex: "<?php" ==> "<?php "
P/S: See my screenshot: http://take.ms/v8G03 and If your issue still … please
Thanks!
Source: http://themeforest.net/item/sns-avaz-responsive-magento-theme/11951628/comments
Good luck!
Parse error: syntax error, unexpected 'Sns_Avaz_Model_Observer' (T_STRING) in /home/ganyobiclothing/public_html/app/code/local/Sns/Avaz/Model/Observer.php on line 1
As its saying on line 1 so probably there is some white space or special character thats resulting in this.

Ruby and ctioga2 issue

I am trying to run ctioga2 and I keep getting the same error:
bash-4.1$ ctioga2
/usr/bin/ctioga2:49:in `require': /usr/lib/ruby/site_ruby/1.8/ctioga2/plotmaker.rb:646: syntax error, unexpected ')' (SyntaxError)
) do |plotmaker, size, options|
^
/usr/lib/ruby/site_ruby/1.8/ctioga2/plotmaker.rb:646: syntax error, unexpected '|', expecting '='
/usr/lib/ruby/site_ruby/1.8/ctioga2/plotmaker.rb:867: syntax error, unexpected kEND, expecting $end
from /usr/bin/ctioga2:49
Do you guys know why this happens?
Not familiar with the code base exactly of tioga2. Based on the error message it was expecting an assignment (=) and ran into a | and )
This is a ruby-1.8 specific bug. It is now fixed in the git repository (commit: be1cc4b).
But stackoverflow is not the place to file bug reports for programs, you're lucky I stumbled upon this one.
For ctioga2, please use either the bug tracker at sourceforge: https://sourceforge.net/p/ctioga2/tickets/ or the one at github if you prefer: https://github.com/fourmond/ctioga2/issues/.

syntax error, unexpected ',', expecting ')'

I just installed Ruby 1.9.2 after having used 1.8.7, as there is a feature I need. I had called many of my methods like this:
do_something (arg0, arg1)
With 1.9.2, i get the following error, syntax error, unexpected ',', expecting ')' and the fix seems to be:
do_something arg0, arg1
But this could take me hours to fix all the cases. Is there a way around this? Why is it an error in the first place? thanks
The extra space is the culprit. Use:
do_something(arg0, arg1)

Resources