Rails Server Controller Error - ruby-on-rails

I have written a rails application but when running rails server I am getting following error
"syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' ...? ? render("result") : Your url have a problem );#output_buf... ... ^"
</div>
</div>
<%= #links.present? ? render("result") : Your url have a problem %>
</div>

You need to enclose strings between " " or ' ' otherwise they will be treated as variables (or classes); Your url have a problem has no "", so that's causing the problem.
Try changing this line:
<%= #links.present? ? render("result") : Your url have a problem %>
to:
<%= #links.present? ? render("result") : "Your url have a problem" %>

Related

Rails: Getting tIDENTIFIER Syntax error

I'm getting an error on the following code:
<%= Warehouse.where(:product sale.product).pluck(:price) %>
Actually it should print the price if Warehouse.product == sale.product. But it doesn't. I'm getting this error:
SyntaxError in OrdersController#show
syntax error, unexpected tIDENTIFIER, expecting ')' ...= Warehouse.where(:product sale.product).pluck(:mrr) );#outp... ... ^
syntax error, unexpected ')', expecting keyword_end ...uct sale.product).pluck(:mrr) );#output_buffer.safe_append='... ... ^
What am I doing wrong?
Thanks in advance!
Try this
<%= Warehouse.where(:product => sale.product).pluck(:price) %>

Rails syntax error missing parenthasizes

I am getting a weird syntax error from rails that I don't understand.
GETTING THE FOLLOWING ERROR:
Showing /home/action/workspace/clinio/app/views/tasks/_task.html.erb where line #3 raised:
/home/action/workspace/clinio/app/views/tasks/_task.html.erb:3: syntax error, unexpected ';', expecting ':'
';#output_buffer.append=( image...
^
Extracted source (around line #3):
<% #uncompletedtasks = #task if #uncompletedtasks?%>
<li id="task_">
<div><%= image_tag "26-mini-gray-checkmark.png" %>
<%= #uncompletedtasks.task %>
</div>
</li>
Trace of template inclusion: app/views/tasks/_task.html.erb, app/views/layouts/application.html.erb
Rails.root: /home/action/workspace/clinio
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:35:in _app_views_layouts_application_html_erb__122972711486791642_46610700'
app/controllers/users_controller.rb:16:inindex'
You don't need that question mark at the end.
<% #uncompletedtasks = #task if #uncompletedtasks %>
(the purpose of this code still eludes me, though. Why would you want overwrite #uncompletedtasks only if it has value?)

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

Rails link_to syntax error: unexpected ',', expecting ')'

I recently attempted to add bootstrap-sass to my rails app, and it seemed to have broken all my links (the links were fully functional before installing the bootstrap-sass gem). I am using ruby 1.8.7.
A sample link I have is:
<%=link_to image_tag ("right_arrow.png", :size => '20x20'), project_step_path(#project, #step.number+1) %>
The error I am getting is:
syntax error, unexpected ',', expecting ')' ...o(image_tag ("right_arrow.png", :size => '20x20'), project_s...
Anyone know how to fix this?
There is an extra-space after image_tag.
image_tag ("right_arrow.png", :size => '20x20')
It should be
image_tag("right_arrow.png", :size => '20x20')

Ruby on Rails string scan and regular expression

I wanted to get image url "http://www.test.com/image.jpg" out from the string:
"<img align="right" alt="Title " src="http://www.test.com/image.jpg" width="120" /><"
Here is the code that I have:
module MyHelper
def getMymage(allDesc)
allDesc = "<img align="right" alt="Title " src="http://www.test.com/image.jpg" width="120" /><"
allDesc = allDesc.scan(src="(\S+)")
end
end
I got the following error:
syntax error, unexpected tAMPER
allDesc = allDesc.scan(src="(\S+)")
syntax error, unexpected $undefined
allDesc = allDesc.scan(src="(\S+)")
How to fix it?
Can't comment on sunkencity's answer, but regex that solves the dash problem is:
/src=\"([a-z0-9_.\-:\/]+)"/i
The regexp is missing a start "/" and some extra stuff
allDesc.scan(/src=\"([a-z0-9_.\-:\/]+)"/i)
but you get an array as a response:
=> [["http://www.test.com/image.jpg"]]
I'd suggest using the matching operator and then use the first match variable:
allDesc =~ /(http:\/\/[a-z0-9_.-i\/]+)/ && $1

Resources