Ruby on Rails 3 - 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" ) %>

Related

Rails: ERROR: compiling partial haml file

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'

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.

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.

problems with indexing, unterminated regexp meets end of file

I wrote this while trying to index data
= form_tag blog_posts_path, method: :get do
%p
= text_field_tag :query, params[:query]
= submit_tag "Search", name: nil
and I get this error and I really don't know how to fix it:
/home/marina/project/app/views/blog_posts/index.haml:15: syntax error, unexpected ')'
));}\n<p></p>\n#{
^
/home/marina/project/app/views/blog_posts/index.haml:15: syntax error, unexpected '<'
));}\n<p></p>\n#{
^
/home/marina/project/app/views/blog_posts/index.haml:15: unterminated regexp meets end of fail
/home/marina/project/app/views/blog_posts/index.haml:15: syntax error, unexpected $end, expecting keyword_end
Extracted source (around line #15):
12: %br
13:
14: = form_tag blog_posts_path, method: :get do
15: %p
16: = text_field_tag :query, params[:query]
17: = submit_tag "Search", name: nil
18:
Yep, that seems an indentation problem. You should indent once the %p and twice the last two lines.

devise + omniauth undefined method `find' for Symbol:Class error

NoMethodError in Projects#index
Showing /home/dave/Documents/exercises/todo/app/views/layouts/application.html.erb where line #18 raised:
undefined method `find' for Symbol:Class
Extracted source (around line #18):
15:
16: <div id="container">
17: <div id="user_nav">
18: <% if user_signed_in? %>
19: Sign in as <%= current_user.email %>. Not you?
20: <%= link_to "Sign out", destroy_user_session_path %>
21: <%else %>
why am i getting this error message?
undefined method `find' for Symbol:Class
im using rails 3.0.7 and devise 1.1.rc0
based on this tutorial http://media.railscasts.com/videos/236_omniauth_part_2.mov
what a lame i just bundle installed devise 1.3.4 and changed secret_token or clear sessions db and *then up and running*
just incase some people might investigate some the cause of this problem just to let you know.