rake db:migrate syntax error (that doesn't exist) - ruby-on-rails

rake db:migrate aborts because of a syntax error
rake aborted!
/Users/Fryed/rails/treebook/db/migrate/20121009215822_devise_create_users.rb:3: syntax error, unexpected '\n', expecting '|'
/Users/Fryed/rails/treebook/db/migrate/20121009215822_devise_create_users.rb:47: syntax error, unexpected keyword_end, expecting $end
But the corresponding lines look like this:
line 3 create_table(:users) do |t
and line 47 end
Why doesn't this work, and how can I fix it?
Many thanks in advance!

You're just missing a trailing |, line 3 should read:
create_table(:users) do |t|
\n means line break - so the error message basically said, "ruby saw a line break, but it was expecting another |"

Related

Ruby DB Migration Error 'rake db:migrate'

I am starting to play around with ruby and setting up my development environment.
I am referencing This Ruby on Rails 'Getting Started Guide' and am down to section 5.5 'Running a Migration'
The problem is when I run the following command
rake db:migrate
I get the following error
C:\Users\someuser\RubymineProjects\my_app>rake db:migrate
rake aborted!
SyntaxError:C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:4: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
t.string :[title
^
C:/Users/someuser/RubymineProjects/my_app/db/migrate/20140718160751_create_articles.rb:5: syntax error, unexpected ']', expecting keyword_end
t.text] :text
^
C:in `disable_ddl_transaction'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Any idea what is causing this and how to fix it?
It looks like you have some extra brackets in your migration that don't belong there. The migration should look like:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
t.text :text
t.timestamps
end
end
end

rake routes--> rake aborted! syntax error, unexpected keyword_end, expecting end-of-input (Mac)

Hello i'm new to Ruby on Rails, and I was trying to set up a blog.
I ran "rake routes" and I got the error copy and pasted below.
I would greatly appreciate help fixing it (have not found anything similar online.)
dhcp-18-111-5-233:blog ronaldoisabeast$ rake routes
rake aborted!
/Users/ronaldoisabeast/Desktop/Rails/blog/config/routes.rb:58: syntax error, unexpected keyword_end, expecting end-of-input
/Users/ronaldoisabeast/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in load'
/Users/ronaldoisabeast/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:inblock in load'
/Users/ronaldoisabeast/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in load_dependency'
/Users/ronaldoisabeast/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:inload'
/Users/ronaldoisabeast/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
paths'
There is some end missing in your config/routes.rb if you can put it here we will be able to find the bug

rake test:functionals throwing syntax error, unexpected keyword_end

When I run the rake task "test:functionals" for my RoR app, it produces this error:
>rake test:functionals
rake aborted!
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/transactions.rb:380: syntax error, unexpec
ted keyword_end, expecting $end
Tasks: TOP => test:functionals => test:prepare => db:test:prepare => db:abort_if_pending_migrations => db:load_conf
ig
I have checked my code for syntax errors. Why would transactions.rb have a syntax error?
You have unmatching blocks in your code, its not in transactions.rb., even if it says it's on transactions.rb its most probably not.
Double check your block openers such as do class def
Also check for . trailing in methods or objects
Example: variable.length.

acts_as_tree and rails 3.2.3, not compatible?

I am using Rails 3.2.3 and acts_as_tree 1.1.0. I have been using acts_as_tree for a handful different projects with earlier versions of Rails 3 (such as 3.1.1.) with no problems but it won't work at all for this version. If it is because of 3.2.3 or something else that I use I have not been able to confirm though.
This is what I have tried, to no avail:
- Using acts_as_tree on several different controllers
- Only using acts_as_tree (with no order statement)
- Run bundle install and bundle update
- Double check that parent_id exist and is integer
First, when I tried this I got at first try:
undefined method `acts_as_tree'
reloading the page (and not doing anything else) caused:
undefined method `key?' for nil:NilClass
then restarting the server caused a failure to launch (the app would crash and not start) with the following error:
/Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require': /Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: odd number list for Hash (SyntaxError)
foreign_key: "parent_id",
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: syntax error, unexpected ':', expecting '}'
foreign_key: "parent_id",
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: syntax error, unexpected ',', expecting kEND
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:79: Can't assign to nil
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:80: syntax error, unexpected ':', expecting '='
counter_cache: nil,
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:80: Can't assign to nil
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:81: syntax error, unexpected ':', expecting '='
dependent: :destroy
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:82: syntax error, unexpected '}', expecting kEND
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:86: syntax error, unexpected ':', expecting kEND
belongs_to :parent, class_name: name,
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:87: syntax error, unexpected ':', expecting '='
foreign_key: configuration[:foreign_key],
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:88: syntax error, unexpected ':', expecting '='
counter_cache: configuration[:counter_cache],
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:89: syntax error, unexpected ':', expecting '='
inverse_of: :children
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:91: syntax error, unexpected ':', expecting kEND
has_many :children, class_name: name,
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:92: syntax error, unexpected ':', expecting '='
foreign_key: configuration[:foreign_key],
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:93: syntax error, unexpected ':', expecting '='
order: configuration[:order],
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:94: syntax error, unexpected ':', expecting '='
dependent: configuration[:dependent],
^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:95: syntax error, unexpected ':', expecting '='
inverse_of: :parent
^
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
from /Users/Christoffer/Documents/Webbprojekt/rails/Presenttips/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53
from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50
from script/rails:6:in `require'
from script/rails:6
which makes me guess there is a compability issue btw Rails 3.2.3 and acts_as_tree. I do not know how to verify this though.
What options do I have? I don't necessarily need to use Rails 3.2.3 but if I downgrade to 3.1.1. (which I tried) I encounter other problems that seem worse (the "file setup" does not seem to be the same).
So, what are my options? Have you experienced this as well? There IS something wrong with acts_as_tree, right?
Looks like there's an open from 2 years ago
opened this issue 2 years ago Does not work with Rails 2.3.8 https://github.com/rails/acts_as_tree/issues/1
Options
acts_as_tree_rails3 gem install acts_as_tree_rails3
or
nested_set https://github.com/skyeagle/nested_set
Edit:
You are right, the new location is https://github.com/amerine/acts_as_tree same author
with a comment
We no longer support Ruby 1.8 or versions if Rails/ActiveRecord older
than 3.0. If you're using a version of ActiveRecord older than 3.0
please use 0.1.1.
Moving forward we will do our best to support the latest versions of
ActiveRecord and Ruby
That's why they did not bother with those opened issues

What's the difference between kEND and $end?

I got this error:
syntax error, unexpected kEND, expecting $end
What's the difference between kEND and $end ?
In english this is stating:
syntax error, unexpected end of file, expecting an end keyword
I agree it's a fairly non-intuitive message.
So the difference is:
kEND = end of file
$end = end keyword
kEND is the end of your file $end is the end tag so, something like
if somethingIsTrue
puts "its true!"
end
Usually when this happens, you forgot to close something with an end.

Resources