trying to create a new rails admin user on heroku console - ruby-on-rails

In the heroku console I'm entering
Admin.create(email:‘me#gmail.com’,username: ‘Me’,password:’pass’,password_confirmation:’pass’)
When I run this I get
SyntaxError: (irb):16: syntax error, unexpected tIVAR, expecting keyword_do or '{' or '('
...reate(email:‘me#gmail.com’,username: ‘Me’,p...
... ^
(irb):16: syntax error, unexpected tLABEL, expecting '='
...me#gmail.com’,username: ‘Me’,password:’pass...
Can anyone help with what's wrong with my Admin.create code?
Thanks

Looks like dodgy quotation marks, or spacing? Does this work? (copy & paste)
Admin.create(email: 'me#gmail.com', username: 'Me', password: 'pass', password_confirmation: 'pass')

Related

Using Faker Gem to Seed Data

I'm attempting to seed my database using the Faker gem, but am getting some error messages and can't see where I'm going wrong. My seeds.rb is:
10.times do
List.create! (
name: Faker::Company.buzzword,
shared_with: Faker::Internet.email,
user_id: 3
)
end
50.times do
Item.create! (
name: Faker::Company.bs,
list_id: Faker::Number.between(1, 10),
delegated_to: Faker::Internet.email,
user_id: 3
)
end
puts "Seed finished"
puts "#{List.count} lists created"
puts "#{Item.count} items created"
And the error messages are:
rake aborted!
SyntaxError: /Users/.../db/seeds.rb:3: syntax error, unexpected tLABEL
name: Faker::Company.buzzword,
^
/Users/.../db/seeds.rb:4: syntax error, unexpected tLABEL, expecting '='
shared_with: Faker::Internet.email,
^
/Users/.../db/seeds.rb:5: syntax error, unexpected tLABEL, expecting '='
user_id: 3
^
/Users/.../db/seeds.rb:11: syntax error, unexpected tLABEL
name: Faker::Company.bs,
^
/Users/.../db/seeds.rb:12: syntax error, unexpected tLABEL, expecting '='
list_id: Faker::Number.between(1, 10),
^
/Users/.../db/seeds.rb:12: syntax error, unexpected ',', expecting keyword_end
/Users/.../db/seeds.rb:14: syntax error, unexpected tLABEL, expecting '='
user_id: 3
^
/Users/.../db/seeds.rb:20: syntax error, unexpected end-of-input, expecting keyword_end
Can anyone clue me in to where I'm going wrong?
In Ruby you should never put whitespace between a method name and the opening parenthesis.
# Syntax error
List.create! (
# Correct
List.create!(
So to expand, your code should look like:
10.times do
List.create!(
name: Faker::Company.buzzword,
shared_with: Faker::Internet.email,
user_id: 3
)
end

Ruby IF statement with OR

if subject.downcase.include? product.name.downcase || body.downcase.include? product.name.downcase
puts "111"
end
Why is the above faulty in ruby? Is there a better way to write this?
This is the resulting error:
SyntaxError: (irb):7: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
... body.downcase.include? product.name.downcase
... ^
(irb):9: syntax error, unexpected keyword_end, expecting end-of-input
This translates to:
if subject.downcase.include? (product.name.downcase || body.downcase.include? product.name.downcase)
You need to add parentheses:
if subject.downcase.include?(product.name.downcase) || body.downcase.include? product.name.downcase
However probably this is more readable:
if [subject, body].any? {|element| element.downcase.include? product.name.downcase}

Rspec syntax error, expecting to close a statement?

I'm playing around with rspec and running into an issue trying to check with Dir.glob. It looks like I'm having an error with closing out my Dir.stub statement, but all of my parentheses match?
syntax error, unexpected tCONSTANT, expecting ')' (SyntaxError)
Facter::Util::Resolution.stubs(:exe...
The code is
Dir.stubs(:glob).with("/opt/test/cli-*/checker").and_return(double("glob", :'exists?' => true)
Facter::Util::Resolution.stubs(:exec).with('checker -version').returns("Version: 1.5")
closing paren missing ) .
.and_return(double("glob", :'exists?' => true) <~~ here
Write as
.and_return(double("glob", :'exists?' => true))

syntax error, unexpected ',', expecting tCOLON2 or '[' or '.' when assigning a class to erb

In my profile.html.erb file I get a syntax error anytime I try to assign a class or id to erb. Below is an example:
<p>"<%= current_user.current_program.name, :id => 'progress' %>" Progress</p>
This gives me the following error:
SyntaxError in Users#profile
Showing /.../app/views/users/profile.html.erb where line #13 raised:
/Users/.../app/views/users/profile.html.erb:13: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
...er.current_program.name, :id => 'progress' );#output_buffer....
... ^
I can't figure out what the syntax error is. I'm totally stumped.
We can reproduce and simplify your problem in a standalone Ruby like so:
require 'erb'
ERB.new("<p><%= name, :a => 'b' %></p>").run
Producing the error:
SyntaxError: (erb):1: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
..."; _erbout.concat(( name, :a => 'b' ).to_s); _erbout.concat ...
... ^
from /Users/phrogz/.../ruby/1.9.1/erb.rb:838:in `eval'
from /Users/phrogz/.../ruby/1.9.1/erb.rb:838:in `result'
from /Users/phrogz/.../ruby/1.9.1/erb.rb:820:in `run'
from (irb):2
from /Users/phrogz/.../bin/irb:16:in `<main>'
Even more simply, taking ERB out of the mix:
a, :b=>'c'
#=> SyntaxError: (irb):3: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
What you have just isn't valid Ruby code. What were you trying to do there? Pass the :id => 'progress' hash as a parameter to the .name method? If so, then drop the comma, and (optionally) include parentheses for clarity:
<p>"<%= current_user.current_program.name( :id=>'progress' ) %>" Progress</p>
And if you're using Ruby 1.9+, you can use the simpler Hash-with-symbol-keys syntax:
<p>"<%= current_user.current_program.name( id:'progress' ) %>" Progress</p>
However, it seems unlikely to me that the name method takes such a hash, so I ask again: what are you really trying to accomplish? What does the name method return, and what HTML output do you want?
Taking a guess, maybe you wanted the text returned by .name to be wrapped in <span id="progress">? If so, you must do so like:
<p>"<span id="progress"><%= current_user.current_program.name%></span>" Progress</p>
Or perhaps using content_tag:
<p><%= content_tag("span", current_user.current_program.name, id:'progress') %> Progress</p>
In Haml this would be:
%p
%span#progress= current_user.current_program.name
Progress
maybe if you remove the comma it will work (is current_user.current_program.name a method that takes a hash as a parameter?)

Lots of syntax errors in HAML view (using spree engine)

I have this simple HAML view, admin.html.haml:
!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml"}
%head{"data-hook" => "admin_inside_head"}
(the view is quite large, I deleted most of it for clarity)
Going to http://localhost:3000/admin I get:
SyntaxError in Spree/admin/overview#index
Showing /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml where line #2 raised:
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected '=', expecting ')'
...ut.attributes({}, nil, :xmlns => "http://www.w3.org/1999/...
... ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:2: syntax error, unexpected ')', expecting '}'
..."http://www.w3.org/1999/xhtml")}>\n <head#{_hamlout.adjust_...
... ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected '=', expecting ')'
...tributes({}, nil, "data-hook" => "admin_inside_head")}></...
... ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected ')', expecting '}'
...ook" => "admin_inside_head")}></head>\n</html>\n", -1, fa...
... ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unknown regexp options - htl
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $undefined
...nside_head")}></head>\n</html>\n", -1, false);::Haml::Util.h...
... ^
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: unterminated string meets end of file
/Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml:3: syntax error, unexpected $end, expecting '}'
Extracted source (around line #2):
1: !!!
2: %html{:xmlns => "http://www.w3.org/1999/xhtml"}
3: %head{"data-hook" => "admin_inside_head"}
Trace of template inclusion: /Users/panayi/Dropbox/Sites/RAILS/engines/core/app/views/spree/layouts/admin.html.haml
The haml gem is loaded correctly (messing with the haml view indentation I get a Haml::SyntaxError), and it worked ok with erb views, before switching the spree views to haml.
Can anyone suggest what to check, to resolve the errors?
I spotted the problem:
Spree uses deface which is incompatible with HAML (see here).
The solution is to disable deface in the environment-specific config file (development.rb, production.rb, etc). Add this:
# Disable deface
config.deface.enabled = false

Resources