What's wrong with this rails syntax? - ruby-on-rails-3

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.

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.

devise error on rails 3

Im getting the following error message:
undefined method `user_registration_path' for #<#<Class:0x10f227cd8>:0x10f5f6d50>
Extracted source (around line #3):
1: <h2>Sign up</h2>
2:
3: <%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
4: <%= f.error_messages %>
5: <p><%= f.label :email %></p>
6: <p><%= f.text_field :email %></p>
I checked everything and i didnt found an error, i had just created the project and installed the plugin.
I was using a old version of the devise plugin in the new version of the ror. =x

Why can't I access this field? (Rails 3)

I really can't figure out why I can't access the user_id field for the class Post. I have it as a field in my database (I can see it, and it isn't blank. Yet for some reason, I'm getting this error:
undefined method `user_id' for #<Class:0x103497448>
Extracted source (around line #10):
7: <h2>Topics</h2>
8: <% #board.topics.each do |topic| %>
9: <% #post = topic.posts(1) %>
10: <b><%= User.find(#post.user_id).username %> says <%= link_to topic.subject, [#board, topic] %></b><br />
11: <% end %>
12: <% end %>
13:
topic.posts(1) will return an array. Hence #<Class:0x103497448>
The right way to get the first post for a topic would be
9: <% #post = topic.posts.first %>
10: <b><%= User.find(#post.user_id).username %> says <%= link_to topic.subject, [#board, topic] %></b><br />
Try <% #post = topic.posts.limit(1) %>

show_for gem gives to_key error

hi i am using show_for gem and it gives me error like: undefined method `to_key' for # in app/views/messages/index.html.erb where line #46 raised:
my view look like these:
46: <%= show_for #messages do |s| %>
47: <%= s.attribute :subject %>
48: <%= s.attribute :message %>
49: <% end %>
my controller code look like:
#messages= Message.all
please help me what i am doing wrong. thanks in advance
I do not know this gem but according to its documentation, show_for is not supposed to receive a collection as argument (#messages) but a single object. I might be wrong.
With this supposition, I would to :
<% #messages.each do |message| %>
<%= show_for message do |s| %>
<%= s.attribute :subject %>
<%= s.attribute :message %>
<% end %>
<% end %>

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" ) %>