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.
Related
I am trying to reset my database.
It isn't working locally or in heroku.
I succuessfully ran each of these commands:
1. rake db:drop
2. rake db:create
3. rake db:migrate
The migrations took a while to succeed. I commented out the ones that were causing a problem and the whole job finishes migrating.
I then try to reset my database with:
4. rake db:reset
I get this error:
initialize_schema_migrations_table()
-> 0.0031s
rake aborted!
NoMethodError: undefined method `name=' for #<University:0x007fc288bdcca0>
/app/vendor/bundle/ruby/2.2.0/gems/activemodel-4.1.9/lib/active_model/attribute_methods.rb:435:in `method_missing'
I can't find anywhere in the code base that has a method called 'name' for university. I have run searches looking for university.name and name near university.
I have updated my gems and run bundle install.
What does this error message mean?
When I try:
rake db:reset --trace
I get:
** Execute db:abort_if_pending_migrations
rake aborted!
NoMethodError: undefined method name=' for #<University:0x007f9a1b24da30>
/Users/em/.rvm/gems/ruby-2.2.2/gems/activemodel-4.1.9/lib/active_model/attribute_methods.rb:435:inmethod_missing'
I have run all migrations and refreshed rake db:migrate
This is the error you get when you are trying to write to a variable that you haven't declared an attr_writer for.
class Foo
attr_reader :bar
def initialize
#bar = 1
end
end
> f = foo.new
=> #<Foo:0xa22ef0c #bar=1>
> f.bar
=> 1
> f.bar = 2
NoMethodError: undefined method `bar=' for #<Foo:0xa22ef0c #bar=1>
from (irb):23
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
It looks like you've got something in your seeds.rb file causing the error.
The reason you're seeing the issue when running rake db:reset but not when running those 3 individual steps is because rake db:reset doesn't run those 3 individual steps.
rake db:reset will run the following:
rake db:drop
rake db:setup
and subsequently, rake db:setup will run these:
rake db:create
rake db:schema:load
rake db:seed
If you only want to do the initial 3 steps (rake db:drop, rake db:create, rake db:migrate), you can run this instead:
rake db:migrate:reset
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
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 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 |"
I have seen the other posts but I am still having trouble. Below is my code. I have several rake tasks where I pass in zero, one or even five arguments. What am I missing?
namespace :my_namespace do
desc 'shows user accounts within the database for the specified customer.'
task :show_user_accounts, [:customer_id] => :environment do |t, args|
cust = Customer.find( args.customer_id.to_i )
cust.users.each do |user|
puts "User Name: #{user.name}\tUser ID: #{user.id}\t"
end
end
end
I am running the task with the following command:
$ rake my_namespace:show_user_accounts customer_id=110
Error:
rake aborted!
Couldn't find Customer with id=0
After much searching around I found that not only did the syntax for a rake task change, but the execution syntax did as well. So, the code of my rake task (above) is correct but my invocation was wrong.
The correct way for running above rake task is:
$ rake my_namespace:show_user_accounts[110]
I found the answer here: http://www.redconfetti.com/2012/01/example-rake-task/