So...
It looks like there are two ways to get started with Spree as far as implementing it into your Rails application, neither of which work...
Method A
$ spree mystore
Result
spree: command not found
Method B
$ rails cart
$ cd cart
$ rails g spree:site
Result
I get spit out the man page for the "rails" command as if it has no idea what I'm talking about.
Usage:
rails new APP_PATH [options]
Options:
-J, [--skip-prototype] # Skip Prototype files
-T, [--skip-test-unit] # Skip Test::Unit files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
-G, [--skip-git] # Skip Git ignores and keeps
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
-b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL)
and so on...
Here's what I've done:
$ sudo gem install spree #and all of its dependencies
My Gemfile:
source :rubygems
# Generic gem dependencies first
gem 'mysql2'
gem 'newrelic_rpm'
# Followed by spree itself first, all spree-specific extensions second
gem 'spree'
gem 'spree_active_shipping', :git => 'https://github.com/spree/spree_active_shipping.git'
gem 'spree_product_assembly', :git => 'git://github.com/spree/spree-product-assembly.git'
gem 'spree_static_content', :git => 'git://github.com/spree/spree_static_content.git'
# EOF
And ran
$ bundle install
So what am I missing, my wonderful S.O. community?
As they described on their Github, you have to a create a new rails application and add gem 'spree' to gemfile and then do bundle install.
Got this figured out.
HAS to be Rails 3. I became a big boy yesterday and upgraded.
Ran into a crapton of problems after this so make sure spree gemversion matches in gemfile and with your gem list (mine was 0.50.2) this doesn't really happen by default.
This
gem 'spree_static_content', :git => 'git://github.com/spree/spree-static-content.git'
has to become
gem 'spree_static_content', :git => 'git://github.com/spree/spree_static_content.git'
in your gemfile, the documentation is wrong.
You have to edit line #6 in /home/user/.bundler/ruby/1.8/spree_active_shipping-cb4f80aeb9c9/lib/tasks/active_shipping_extension_tasks.rake to reflect "RAILS_ROOT" instead of "something_shippy_thingy.root"
You have to run
rails g spree_product_assembly:install
rails g spree_static_content:install
rake db:migrate
So yeah, a lot of digging and most of this NOT in the documentation. Hopefully someone else finds this and its useful
Related
I have the puma gem in my Rails 4.1.8 Gemfile because I want to use it as the default webserver in all environments. That works fine.
# Gemfile
gem "puma"
In development I am using mailcatcher which means that I'd like to include it as a dependency in my Gemfile.
# Gemfile
group :development do
gem "mailcatcher"
end
This causes the default webserver to be set to thin. This appears to be an unintended consequence of mailcatcher, but it brings up a specific question. Can I create a group that bundler obeys to install Gems, but that Rails ignores? I tried something like this but Rails is still loading the contained gems.
# Gemfile
group :mailcatcher do
gem "mailcatcher"
end
You can alias rails s command... For example export alias rs="rails server puma" and now rs will start puma. This way you are free to use any webserver you want )
If you want to make it really default you can add something like this
require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)
to the rails script.
I don't know if this will work or not, but what about:
gem "mailcatcher", :require => false
Ref: Bundler: What does :require => false in a Gemfile mean?
Mailcatcher specifically states to not put it in your Gemfile.
Please don't put mailcatcher into your Gemfile. It will conflict with your applications gems at some point.
Instead, pop a note in your README stating you use mailcatcher. Simply run gem install mailcatcher then mailcatcher to get started.
I'm in my app folder, but the command rails s is not working. I read through quite a few posts on Stack Overflow, and most of them seem to be from users who are not in their app directory.
In addition, I built a few other apps. I checked those, and the Rails server works for all of those apps. This is the only one where I can't get it to launch.
Output of which rails:
/Users/jmcrist/.rvm/gems/ruby-2.0.0-p247/bin/rails
Output of rails s:
MacBook-Pro:first_app jmcrist$ rails s
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/jmcrist/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip Git ignores and keeps
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Suppress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
I'm working through Hartl's Rails Tutorial, and he makes quite a few modifications to the gemfile. I am wondering if this might be the cause?
source 'https://rubygems.org'
gem 'rails', '3.2.13'
group :development do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end
It seems to think you are not in a rails directory (your output is saying the only valid way to use rails is with rails new).
Depending on your version, Rails identifies this differently. On 3.2, it checks for a file at script/rails. Now that 4.0 has been released, it looks for either script/rails or bin/rails (https://github.com/rails/rails/blob/207fa5c11ddf1cfd696f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6)
Presumably you can get around this by creating the file rails in your script directory (if you do not have a script directory, create one in the root of your app):
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
Of course, it's worth wondering why you don't have this file in the first place. Might be worth making sure your rails is the version you want to be using first (rails -v if the version is newer, this post will show you how to create the new app using the older version).
Possible reasons:
you are not in a directory that contains a full rails app
your bin directory might me empty, try to run rake rails:update:bin (for Rails 4) or rails app:update:bin (Rails 5)
All the above answers didn't help me. What solved my problem for Rails 4 was to run command in the root directory of my application:
rake rails:update:bin
After that running rails s was running as expected.
If you use rvm or rbenv for instance to keep multiple ruby versions, maybe your default rails version for that specific ruby version is different than the project you are trying to run and therefore it's not being able to detect your application.
To make sure you are using the right rails version you can compare both results. This is what I've got:
$ rails -v
Rails 3.1.0
to
$ bundle exec rails -v
Rails 5.0.0.1
In this case, you can keep the default rails version and then use:
$ bundle exec rails server
Or install the specific rails gem to that very ruby version with:
$ gem install rails -v 5.0.0.1
$ rails -v
Rails 5.0.0.1
And then get it working with the less verbose command:
$ rails s
I hope this becomes helpful to other folks in the same situation!
You likely have not bundled your gems yet:
# from command line
bundle install
I had this problem, took me a few minutes to realize I'd forgotten to change active Ruby version with chruby. Different Ruby implied a different Rails version, which looked for the relevant file in another folder.
First check with your location path and then
bundle install
If still does not work, enter
/bin/bash --login
bundle install
This works for me.!!!(NOTE: run this commands into rails app)
rake db:migrate RAILS_ENV=development;
Run this command to generate /bin
rake rails:update:bin
OR
rake app:update:bin
=============================================
Then you will get this kind of screen(In that Go with Y)
bin/rails? (enter "h" for help) [Ynaqdhm] Y
Then you can start the server using
rails s
I'm not sure if this sort of thing is very common, but I keep finding myself trying to create gems that are just wrappers around a Rails application.
My gem will have a generator to create a config.ru but the Rails application will live inside the gem's lib directory. I need to know how to "embed" a Rails application and configure it so that it can be run inside the gem.
For example:
$ mygem new project
mygem created a directory called "project" with the following files:
project/config.ru
project/widgets/
project/foobars/
My gem will also generate some directories that will need to be added to Rails somehow so that I can access the code in those directories from the Rails app living inside the Gem.
Any help or advice you can give me would be appreciated.
To clarify, I'm not trying to create a Rails engine, or plugin to a Rails application. I'm trying to create a fully-fledged Rails application, but package it as a gem so that a user of my gem can run the gem (the rails app) without needing to know that it's using Rails behind the scenes.
Update: Okay, I've got a little bit working now. I've created the gem and generated the rails project inside the gem's lib directory.
$ bundle gem my_gem && cd my_gem/lib
$ rails new my_gem --skip-bundle
Which leaves me with:
my_gem/
my_gem.gemspec
bin/my_gem
lib/
my_gem.rb
my_gem/
version.rb # generated by bundler
# the rails app:
app/
config/
Gemfile
...etc
Since this gem requires Rails, I started adding the gems defined in the Rails Gemfile as dependencies in the gem's Gemspec, but I'm a little confused as to how to handle the assets group in the Gemfile.
# Rails Gemfile
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# gemspec
Gem::Specification.new do |gem|
gem.name = "my_gem"
# ...
gem.add_dependency 'rails', '3.2.8'
gem.add_dependency 'sqlite3'
gem.add_dependency 'jquery-rails'
# how to add the assets group gems?
end
Try this and see if it helps you make progress.
Gems are just directories of files, and you can put whatever files you want into a gem.
Create:
Create a blank gem full-blown Rails project:
$ bundle gem my_gem
Then a Rails app:
$ rails new my_app --skip-bundle
Copy the Rails files into the gem:
$ cp -R my_app/* my_gem
Bundle everything into your Rails app:
$ cd my_gem
$ bundle install --binstubs --path vendor/bundle
$ cd -
Make the Rakefile have the gem tasks and the Rails setup:
#!/usr/bin/env rake
require "bundler/gem_tasks"
require File.expand_path('../config/application', __FILE__)
MyApp::Application.load_tasks
Verify that it starts:
$ rails server
Load Path:
To control where Rails looks for files, such as "external" configuration files, you can use the file config/application.rb with any directory paths like this:
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{config.root}/../customdir )
Note the ".." which means go above the Rails directory. This gives you a path relative to the gem.
If you prefer you can specify an absolute path, for example if you know the user will always keep his external files in "~/myfiles/". You can also choose to use ENV vars to send in whatever directory you want.
If you read about load path capabilties, look for lines that are shorthand for adding a directory to the front of the load path because you may want to put your external diretories first:
$:.unshift File.dirname(__FILE__)
Gem Build:
Edit my_gem.gemspec to add your own description, homepage, summary, etc. then build:
$ gem build my_gem.gemspec
Successfully built RubyGem
Name: my_gem
Version: 0.0.1
File: my_gem-0.0.1.gem
Now your Rails app is packaged as a gem.
The config.ru should be a typical Rails one. No special changes AFAIK.
When your user wants to install your app:
$ gem install my_gem
The gem will install in the user's typical gem directory. If you want to adjust this, see this page on rubygems: http://docs.rubygems.org/read/chapter/3
Crate:
You may also want to investigate the Crate project:
Crate: Packaging Standalone Ruby Applications
http://www.slideshare.net/copiousfreetime/crate-packaging-standalone-ruby-applications
Rack:
To use config.ru here is the typical Rails setup:
# Rails.root/config.ru
require "config/environment"
use Rails::Rack::LogTailer
use ActionDispatch::Static
run ActionController::Dispatcher.new
For your project, you want to require some files before Rails. You'll want to learn about the Ruby "require" and how it finds files using LOAD_PATH.
The easy way:
# Rails.root/config.ru
require_relative 'filename'
require "config/environment"
Or to put the user's custom directory up couple directory levels:
require './../../filename' # not the best for security
Or to use an absolute path, read about File.expand_path:
File.expand_path(__FILE__)
Or to use the current directory and put it on the load path:
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'filename'
Lots of choices for you to consider. Hope this helps!
What about the question, "How am I going to run the Rails application inside the gem?".
A Rails application has controllers and views to run a web server. What you need are actions to create, list, update, and destroy. Exposing these actions without a web server is essentially having such methods in a class. That's a normal standard type of gem in the first place.
So maybe your questions is really, how do I write a gem where I have ActiveRecord, and the other Rails stuff.
First, you need to make your gem dependent on the Rails gems you need. You do this in the gemspec file for your gem.
Then it really is just a matter of your gem code doing a require of the right Rails gems you need.
I'm not sure if this will help, as I read through everything and I couldn't find the motivation behind why you were doing this. One of the reasons I came up with was making something that can be used on a desktop environment. In that case you could try using something like Bowline. If you just want to provide an application that others can download and use and install themselves, then you can probably assume they can follow at least basic developer kind of instructions and you could just provide the whole app on github or as a zip file. See an example of someone else doing something similar over on Fat Free CRM's github page.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do you upgrade from Rails 3 to Rails 3.1 beta?
This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
Update the rails version specified in my Gemfile to use the latest release candidate:
gem 'rails', '3.1.0.rc4’
Update the bundle:
bundle update
Then update the project with the rake command:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
I found some details about that are here:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.
I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
Upgrading Rails
Update: be cautious of using your system rake, as rake has been upgraded.
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
An example
While converting an older rails 2.3.4
app to 3.0 I crashed and burned while
changing one file at a time over
within the project. Needless to say
that was a flawed strategy, but I did
learn a little along the way. I ended
up skipping 3.0 and moving to 3.1beta1
with a fresh app, and copied my app
and public folders in after getting
the migrations right. That move had a
couple of outstanding issues, the most
important being that I didn’t use
rails edge for creating the new app
(thanks for the tip RubyInside).
First snag the latest rails into an
easy to reference location:
cd ~/goodtimes
git clone
https://github.com/rails/rails.git
My path includes a ~/Desktop/Dropbox/
so my code is available everywhere.
Then refer to that rails exec for
building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
References:
How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now
The Four Horsemen of Rails 3.1beta, Coffee-Script, jQuery, SCSS and Assets
Rails 3.1beta deployed to Heroku from your iPhone
Reversible Migrations
I recommend updating your Gemfile to use edge rails. For example:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.
If i understood your question correctly this is how:
gem install rails --pre
My gem file looks like:
group :development, :test do
gem 'rspec-rails'
gem 'annotate-models', '1.0.4'
end
I ran 'bundle install' and it installed the annotate-models bundle.
If I type: annotate I get a command not found error.
If I type: bundle show annotate I get a 'could not find gem annotate in the current bundle.
If I type bundle show annotate-models it says it installed in:
/Library/Ruby/Gems/1.8/gems/annotate-models-1.0.4
typing:
annotate-models
doesn't work either.
I'm following along in railstutorial.org and got stuck at this point.
Edit: Better version (using Bundler to install it only for the current project)
Add gem 'annotate' to Gemfile
Run $ bundle install
Run $ bundle exec annotate
Edit2: Seems you have to explicitly specify annotate version for now, so in Gemfile put gem 'annotate', '2.4.1.beta1' (which is a prereleased beta gem that works with the latest version of activerecord as opposed to specifying the github repo directly)
Edit3: 2.5.0 final is out now, so hopefully no need to force a beta version any more, just getting the latest should work!
Old version (with installing the gem on a system level too):
If running Rails 3 the drill is:
Run $ sudo gem install annotate
Add gem 'annotate' to Gemfile
Run $ bundle install
Run $ annotate
Be happy :)
You should run the command inside your bundled environment with:
$ bundle exec annotate
Check out the man page for more details.
The most voted answer didn't fully work for me, as I was getting and additional error when follow the proposed solution:
undefined method `namespace' for main:Object (NoMethodError)
I'm including below what worked for me (I'm using Ruby 1.9.2 and Rails 3.1.3 under Ubuntu 11.10):
Install annotate
$ gem install annotate
Modify Gemfile adding the following line
gem 'annotate',
:git => 'git://github.com/jeremyolliver/annotate_models.git',
:branch => 'rake_compatibility'
Install bundle
$ bundle install
Now you can use annotate as follows:
$ bundle exec annotate
I'm new to this, but I was having this problem doing the rails tutorial, but by adding the gems bin path to the PATH env variable I was able to fix it. (Just like gertas said a few posts above)
First in the command prompt:
gem list -d annotate
and you'll get a result that says something like
: annotate-models (1.0.4)
Author: Dave Thomas
Rubyforge: http://rubyforge.org/projects/annotate-models
Homepage: h'ttp://annotate-models.rubyforge.org
Installed at: C:/ruby192/lib/ruby/gems/1.9.1
the key line is:
Installed at: C:/ruby192/lib/ruby/gems/1.9.1
So in this case add a /bin to that path, For example I used: C:\ruby192\lib\ruby\gems\1.9.1\bin is what you want to add to your PATH environment variable.
To change your PATH environment variable on Vista do the following go to: control panel >> system >> advanced system settings(link on the left). Once the box opens up,click the Advanced tab and then the Environment variables button. Then on the system variables find the PATH variable and click the Edit button. Since paths are separated by semi-colons, add
;C:\ruby192\lib\ruby\gems\1.9.1\bin
At the end of the variable value field.
It should look like
`some/path;some_other_path;C:\ruby192\lib\ruby\gems\1.9.1\bin`
when you finish
Save it, and close and reopen the command prompt. annotate and rspec started to work for me after that. Good luck.
For me the answer was this one:
http://news.railstutorial.org/model-annotation
Use
gem 'annotate', '2.4.0'
instead of
gem 'annotate-models', '1.0.4'
It looks like the gem name was changed at RubyGems.org.
I think your PATH env variable lacks path to gems bin directory.
I guess it should be: /Library/Ruby/Gems/1.8/bin
You can use it for Rails 4, add gem in your gem file gem "annotate", "~> 2.5.0" and run following command
rails g annotate_models:install
instead of
rails g annotate:install
Then run following command to add schema information after model class
bundle exec annotate -p after
or can use following for before
bundle exec annotate -p before
If bundle exec annotate doesn't work, try:
rake annotate_models