Lots of syntax errors in HAML view (using spree engine) - ruby-on-rails

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

Related

syntax error, unexpected keyword_in, expecting '|'

What is wrong with that code?
%body
- In.all.each do |in|
= link_to in.name, categories_path(in: in.name)
= yield
My syntax errors:
/home/ubuntu/workspace/app/views/layouts/application.html.haml:10: syntax error, unexpected keyword_in, expecting '|' In.all.each do |in| ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:11: syntax error, unexpected keyword_in, expecting ')' ...e_false_true_false(( link_to in.name, categories_path (in: i... ... ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:11: syntax error, unexpected ( arg, expecting keyword_do or '{' or '(' ...k_to in.name, categories_path (in: in.name) ... ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:12: syntax error, unexpected ')', expecting tSTRING_DEND ));}\n", 0, false);end;_hamlout.push_text(" <end>\n #{ ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:12: syntax error, unexpected keyword_end ));}\n", 0, false);end;_hamlout.push_text(" <end>\n #{ ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:14: syntax error, unexpected '}', expecting tSTRING_DEND ));}\n</body>\n", -1, false);::Ha... ^
/home/ubuntu/workspace/app/views/layouts/application.html.haml:14: unterminated regexp meets end of file
/home/ubuntu/workspace/app/views/layouts/application.html.haml:14: syntax error, unexpected end-of-input, expecting tSTRING_DEND
Thanks!
in is a reserved keyword. Try using something else as the block variable.

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?)

Syntax errors in html file

Not exactly sure what the errors are indicating. I am getting the following syntax errors:
compile error
app/views/students/student_fail.html.haml:33: syntax error, unexpected tIDENTIFIER, expecting ')'
... :student_fail_attribute params[:StudentFailState.true], pa...
^
app/views/students/student_fail.html.haml:33: syntax error, unexpected ')', expecting '='
...method], params[:text_method])
^
app/views/students/student_fail.html.haml:39: syntax error, unexpected kENSURE, expecting kEND
...\n", -2, false);_erbout;ensure;#haml_buffer = #haml_buffer.u...
^
app/views/students/student_fail.html.haml:40: syntax error, unexpected kENSURE, expecting kEND
app/views/students/student_fail.html.haml:42: syntax error, unexpected $end, expecting kEND
Here's the html:
:ruby
fields = if #step == 1
[ select_tag(:id, options_from_collection_for_select(Student.passed, :id, :selector_label, #student.id), :size => 10) ]
elsif #step == 2
form_for #student do |f| f.collection_select( :student_fail_attribute params[:StudentFailState.true], params[:value_method], params[:text_method])
end
#fields << render_sequence_nav(sequence_info, students_path)
fields << render(:partial => "resources_partials/sequence/nav", :locals => sequence_info.merge({:cancel_url => {:controller => :dashboard}}))
= render_form { fields }
Thanks for any response.
I think you are missing a comma between :student_fail_attribute and params[:StudentFailState.true].
You might want to think if params[:StudentFailState.true] is supposed to be there at all, unless it returns the collection you will most likely not get the expected results.

Resources