Rails: ERROR: compiling partial haml file - haml

I'm getting the following error on the rails server when I press my 'new task' button on my app:
Processing by TasksController#new as JS
ERROR: compiling _app_views_tasks__task_form_html_haml__3289363938348847619_70231363971640 RAISED /app/views/tasks/_task_form.html.haml:4: syntax error, unexpected ')'
));}\n</div>\n<div class='modal-body'>\n #{
^
/app/views/tasks/_task_form.html.haml:8: unknown regexp options - dv
/app/views/tasks/_task_form.html.haml:8: syntax error, unexpected $undefined
));}\n</div>\n<div class='modal-footer'>\n #{
^
/app/views/tasks/_task_form.html.haml:8: syntax error, unexpected keyword_class, expecting keyword_do or '{' or '('
));}\n</div>\n<div class='modal-footer'>\n #{
^
/app/views/tasks/_task_form.html.haml:8: syntax error, unexpected $undefined
));}\n</div>\n<div class='modal-footer'>\n #{
^
/app/views/tasks/_task_form.html.haml:10: syntax error, unexpected '}', expecting keyword_end
));}\n</div>\n", -1, false);::Ham...
^
Below is the code on _task_form_html_haml:
.modal-header
%h1 New Task
= simple_form_for task, class: 'clearfix' do |f|
.modal-body
= f.input :title
= f.input :note
= f.input :completed
.modal-footer
= f.submit 'Save', class: 'btn btn-primary'
I've tried to find out more about compiling errors, partials, haml but have had no luck so far. Can anyone point me in the right direction?

You have this line:
= simple_form_for task, class: 'clearfix' do |f|
that looks like it’s opening a block, but there is nothing indented below it to be the blocks contents.
You just need to correctly indent your code:
.modal-header
%h1 New Task
= simple_form_for task, class: 'clearfix' do |f|
.modal-body
= f.input :title
= f.input :note
= f.input :completed
.modal-footer
= f.submit 'Save', class: 'btn btn-primary'

Related

Rails syntax error - cant' find the reason for it

I'm trying to achieve the following, by pushing a button on a page the user to get a random item from the database which will be showed, but will have an attribute editable. The problem I hit into, is the following I don't know how to pass an random id(valid in the database), to be rendered in my partial, but still to be able to update the specific attribute.
Problem from the title:
SyntaxError in Tasks#main
Showing /home/bogdan/ex/bored/app/views/tasks/main.html.erb where line #1 raised:
/home/bogdan/ex/bored/app/views/tasks/main.html.erb:1: syntax error, unexpected ',', expecting ')'
...uffer.append= form_for (:task, :url => {:action =>'rand_tas...
... ^
/home/bogdan/ex/bored/app/views/tasks/main.html.erb:1: syntax error, unexpected ')', expecting keyword_end
...url => {:action =>'rand_task'}) do |f|#output_buffer.safe_co...
... ^
../app/views/tasks/main.html.erb:8: syntax error, unexpected keyword_ensure, expecting $end
Extracted source (around line #1):
1: <%= form_for (:task, :url => {:action =>'rand_task'}) do |f|%>
2: <%= render(:partial => "rand_show", :locals => {:f => f}) %></p>
3: <%end%>
4:
Trace of template inclusion: app/views/tasks/main.html.erb
I was trying to pass the rand_task output object to the _rand_show.html.erb and afterwartds call a new editable form only for the attr i'm intressted in by the id
form:
<%= form_for(#task = Task.new) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, :disabled=>true %>
</div>
<div class="field">
<%= f.label :category %><br />
<%= f.text_field :category, :disabled=>true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
random method:
def rand_task
if params[:id] == 'random'
#task = Task.order('RANDOM()').first
else
#task = Task.order('RANDOM()').first // if not i get a nill related error.
end
end
Please help why do i get the above mentioned error? IS the concept i'm thinking about wrong?
<%= form_for (:task, :url => {:action =>'rand_task'}) do |f| %>
^
The problem is the space between form_for and (. If you remove the space it should work.

Why doesn't my partial work with slim and Rails 3.2?

I'm using Rails 3.2 and instead of ERB, I am using slim.
Here is my form partial:
= simple_form_for #game, :html => { :class => 'form-horizontal' } do |f|
The syntax error I am getting is:
_form.html.slim:1: syntax error, unexpected ')' ... => 'form-horizontal' } do |f|))).to_s));
But I don't know where it expects to put the ')'?
Thanks
The syntax should be:
= form_for([#resource], html: { multipart: true }, remote: true) do |f|
Try substituting your values.
I was not able to find the correct documentation for slim form helper.

What's wrong with this rails syntax?

Well, I hate using SO as just a syntax checker, but for the life of me I cannot figure out why I get thi error
where line #8 raised:
unexpected $end, expecting keyword_end
Here is the offending code:
5: <%= f.input :allele2 %>
6: <%= f.input :run_date %>
7:
8: <%=f.association :gmarkers, :collection => Gmarker.all(:order => 'marker'), :prompt => "Choose a Marker", :label => "Marker" %>
9:
I'm using the SimpleForm gem, and am not too familiar with it yet (obviously!)
tia,
--rick
You're missing an <% end %> after your last line there, line 8.

Rails error: can't convert Symbol into Integer

Using the google maps API and rails 3.2.1 I have page allowing to move the business marker on a map to correct it's position. The business model has latitude and longitude (amongst others). The relevant part is:
<%= form_for :business, :url => { :action => "updatemap" }, :id => 'updatebutton' do |f| %>
<%= f.hidden_field :latitude %>
<%= f.hidden_field :longitude %>
<br />
<%= f.submit "Save" %>
<% end %>
The method updatemap is:
def updatemap
#business = Business.find(params[:id])
#business.latitude = params([:business][:latitude])
#business.longitude = params([:business][:longitude])
if #business.save!
redirect_to business_path(#business), :flash => { :success => "The business was updated!" }
else
render 'changemap', :flash => { :error => "An error occured." }
end
end
Running the debugger, params([:business][:latitude]) and params([:business][:longitude]) give the correct value of the new map coordinates (e.g. "45.273739" for latitude). But there is an error:
TypeError in BusinessesController#updatemap
can't convert Symbol into Integer
(the line of the error is the #business.latitude = params([:business][:latitude]) line)
I also tried with
...
if #business.update_attributes(params[:business])
...
but the error is the same. What causes the error and how can I correct it?
You are writing params([:business][:latitude]) rather than params[:business][:latitude]. That means that [:business] is actually a method call on self, rather than params. Presumably the class which this code is part of has a [] method, but it expects an integer rather than :business.

Ruby on Rails 3

Learning Ruby on rails from Michael Hartl
I am following the book and have come across a problem when inserting an image, the error that is produced is here
SyntaxError in Pages#home
Showing /Users/richardhardesty/Sites/rails_projects/beginning/app/views/layouts/application.html.erb where line #17 raised:
/Users/richardhardesty/Sites/rails_projects/beginning/app/views/layouts/application.html.erb:17: syntax error, unexpected ':', expecting ')'
...pend= ( image_tag('logo.png' :alt =>'Sample App' :class =>...
... ^
/Users/richardhardesty/Sites/rails_projects/beginning/app/views/layouts/application.html.erb:17: syntax error, unexpected ':', expecting ')'
...go.png' :alt =>'Sample App' :class =>"round" ) );#output_b...
... ^
/Users/richardhardesty/Sites/rails_projects/beginning/app/views/layouts/application.html.erb:17: syntax error, unexpected ')', expecting keyword_end
...mple App' :class =>"round" ) );#output_buffer.safe_concat('
... ^
Extracted source (around line #17):
14: <body>
15: <div class="container">
16: <header>
17: <%= image_tag('logo.png' :alt =>'Sample App' :class =>"round" ) %>
18: <nav class="round">
19: <ul>
20: <li><%= link_to "Home", '#' %></li>
Trace of template inclusion: app/views/layouts/application.html.erb
I have tried altering the the quotes and brckets and different errors are listed but the problem doesn't go away.
Any help would be great thanks.
You need commas between the arguments in the image_tag method:
<%= image_tag('logo.png', :alt =>'Sample App', :class =>"round" ) %>