Issue with custom rails engine db:migrate rake task - ruby-on-rails

In rails 3.1 you can use the awesome rake task to copy in migrations as seen below from your engine.
rake my_engine:install:migrations
This normally works perfectly if i direct my Gemfile to the git repository or via :path.
However, if i just use the ruby gem directly
gem 'spud_admin'
my rake task disappears
Any ideas why this rake task disappears?

Well, I had a similar problem and managed to solve it thanks to jipiboily's comment. I have an engine called 'myEngine2' so I tried to call it like that:
rake myEngine2:install:migrations
but this failed. I than typed
bundle exec rake -T
there was a line:
rake my_engine2_engine:install:migrations # Copy migrations from
my_engine2_engine to application
I gave it a shot and it worked. Maybe it's the same problem in your case?

Issue was resolved. It had something to do with how jeweler had structured the gem environment. Switching to bundler and using rails plugin new seems to have resolved the issue.

Related

Rake says "Don't know how to build task X", but "rake -T" lists it anyway - why?

I have a new OS X El Capitan setup with Ruby 2.2 (Macports), Rails 4.2.4 and Bundler for an existing app. Among a lot of other gems, this app uses parallel_tests to make good use of my 8-core machine. rake -T lists all the parallel test and spec tasks fine and in the past I could execute them. But when I do this now, after the upgrade, I just get
$ /opt/local/bin/rake parallel:prepare --trace
rake aborted!
Don't know how to build task 'parallel:prepare'
/opt/local/lib/ruby2.2/2.2.0/rake/task_manager.rb:62:in `[]'
/opt/local/lib/ruby2.2/2.2.0/rake/application.rb:149:in `invoke_task'
What can cause a task to be listed in rake -T, but not be found when I try to execute it?
In this case, the reason was that I had put the gem in question inside a group :test in my Gemfile. Apparently this caused the problem, removing it from the group and making it available globally resolved the problem (after calling bundle again).
I don't know whether this is a generic solution, however.

rails heroku asset precompile fail due to rake version

When I tried to push to heroku I get this msg:
rake aborted!
undefined method empty? for nil:NilClass
(in /tmp/build_3d16ad44-0015-4ecb-a7cf-a41959f03f82/app/assets/stylesheets/application.css.scss)
Upon tracing it, I realized that it's because
rake aborted!
You have already activated rake 10.0.3, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this.
This may be a really dumb question, but I am not sure how I am supposed to use bundle exec to do this for heroku? Please help. Thanks.
In case anyone else runs into a similar issue. The problem was that heroku was using ruby 2.0 with all their new apps so in order to do that you have to put whatever ruby version you are using on the gemfile then reset git by typing git reset --soft HEAD~ and then git reset HEAD public/assets into your command line. And rm -r public/assets if you have untracked files in public/assets. Then save the changes and push up to your new site.
So if your app uses an older version of ruby than 2.0, you will have to make similar changes until the bug (sprocket?) is fixed.
Inside the project directory in terminal:
gem list rake
You will see more than one version. If so, then remove the version you don't need (i.e. 10.0.3 in your case) by command:
gem uninstall rake
It will ask you specific version to select from list, choose one and press enter.
Or, you can also update to specific rake version
bundle update rake -v '0.9.2.2'

I can not run the task of rake refinery:testing:dummy

guys! I am a newbie for Ruby on Rails and refinerycms.
Currently, I am study the refinerycms. I want to find all the missing key so as to translate refinerycms. According to the tutorial, I should run the command
bundle exec rake refinery:testing:dummy_app
so as to enable additional useful rake tasks. But when I run this command, it says
rake aborted!
Don't know how to build task 'refinery_testing:dummy_app'
Does any one know the reason?
BTW, I have already added the gem "refinerycms-testing" to Gemfile and installed it already, and I also in the root directory of the project.
I think your problem is that you are not in the good directory.
cd vendor/extension/your_extension_name
bundle exec rake refinery:testing:dummy_app
Hope it helps,
-frbl

Installing migrations from engine won't work

I created a new engine in Rails 3.1.3 and apparently there's that rake task that copies over all migrations. I tried following rake abc:install:migrations which threw:
rake aborted!
Don't know how to build task 'abc:install:migrations'
(See full trace by running task with --trace)
I also tried rake abc_engine:install:migrations with the same result.
Then I read bundle exec rake railties:install:migrations or bundle exec rake railties:install:migrations FROM=abc_engine should do the trick too but no success. Nothing was copied even though no error was thrown.
My migrations are located in db/migrate/ within the engine folder and I ran all commands above from spec/dummy/
Does anyone know how to use this new rake task in order to copy migrations from the engine?
I ran this instead:
rake railties:install:migrations
And my migrations were copied from the engine.
Hope this helps.
I finally got found/got lucky with my (similar) issue. For the first error, it just disappeared, not sure why. Then I figured out that I didn't created the migrations using the usual file name format, so the ActiveRecord::Migrator.migrations method was ignoring them.
If the app you're mounting the engine to doesn't already have ActiveRecord (i.e. you're introducing ActiveRecord to your host app for the first time by mounting the engine), you can get this error as well. Specifically, you'll get this error if you don't have require "active_record/railtie" in your application.rb, or if it's commented out. That line is what enables the rake railties:install:migrations task, which is defined here. rake railties:install:migrations is, in turn, called by the rake abc_engine:install:migrations task here.
Tl;dr: try adding require "active_record/railtie" to your application.rb if it's not already there.

issues with Spree

I am trying to install and run Spree on my local machine by following the steps mentioned in Getting started with Spree
However, when I start the server I get the following error:
Could not find table 'pages'
Can someone please help me out with this?
Solved the issue!
Generated the following generators:
spree_static_content and spree_product_assembly which did the magic!
Could not find table 'pages' means rails is not being able to find that table in the database.
In those instructions, review the section 'configuring the database' and then '4.6 Populating the Database'.
It sounds like you want to give spree a go, but don't have experience with Rails.
The spot where you are stuck is not something specific to spree, its a step required in setting up all rails projects referred to as database migration.
For what you need to know about migrations the official Rails Guides are great.
http://guides.rubyonrails.org/migrations.html
For a comprehensive intro to Rails which may also answer a few of your other questions, check out http://railstutorial.org/ruby-on-rails-tutorial-book
If you just want to try stuff.. the spree tute is on track
Do these steps again..
(If it generates an error, to a rake db:drop first to get rid of what you have already done)
rake db:create
rails g spree:site
rake spree:install
rake spree_sample:install
rake db:bootstrap
rake db:migrate
rake db:seed
rake db:sample
rake db:admin:create
Here is what I did to get Spree up and running:
Create a new rails project:
$ rails new spree_project
Add these 5 gems to the projects Gemfile (/spree_project/Gemfile):
gem 'spree', :git => 'git://github.com/spree/spree.git'
gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'
gem 'spree_gateway', :git => 'git://github.com/spree/spree_gateway.git'
gem 'spree_usa_epay'
gem 'spree_skrill'
Run a bundle install and setup the database (rake db:bootstrap did not work for me)
$ bundle install
$ rake db:migrate
$ rake db:seed
$ bundle exec rake spree_sample:load
The 'pages' table is used by the spree_static_content gem. You can either remove the gem from your gemfile, or you can generate migrations for the static content gem:
rails generate spree_static_content:install
If you've included the 'spree_product_assembly' gem as well, you'll want to do the same for it:
rails generate spree_product_assembly:install
Then, reset the database (just to make sure)
rake db:bootstrap
rake db:admin:create
I ran into similar issues after trying the http://spreecommerce.com/documentation/getting_started.html instructions, but it seems to have created a nice demo app after taking these additional steps.

Resources