How to customize spree commerce? - ruby-on-rails

I have installed Spree on a Windows machine, added sample data and accessed the admin.
But now what?
How do I create a new page or URL?
I don't find any controllers or files in my rails project folder. Do I have to change the location where Spree is downloaded?

But now what?
Spree is "developer friendly", which means you'll need to use the developers mindset as you're building your application. To create a new page, you'll have to follow the Rails-Way. If you run bin/rake routes you'll see all of the routes generated for you.
To generate a path in Spree, you need to call something like spree.root_path. If you have the same path named in your main application, then you'll have to call main_app.root_path. This way rails knows you want your own root path, not Spree's.
For some best practices, you should checkout this blog post: http://blog.benmorgan.io/post/102924399166/customizing-spree-some-best-practices. (My blog also has a lot of Spree content in it.)
I don't find any controllers or files in my rails project folder. Do I have to modify the location where the spree is downloaded?
Bundler installs Spree which is then stored via rvm or rbenv in its appropriate location. All you have to do is add:
gem 'spree', github: 'spree', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'
Or you could use Solidus which I'm now using instead of Spree; currently moving all active Spree projects over to this one.
What I recommend:
Don't use the Spree Frontend.
Understanding how the models work should be enough for you to get started. Making a new Spree::Order object should be quite simple. Then its just Spree::Order.next! and you can start checking things out. To add products to an order, you just order.contents.add Spree::Variant.first, 1 and you've got a new line item in the DB.
Read the source code.
Spree is, honestly, ~4 rails applications. 1 for the models (core), 1 for the storefront (frontend), 1 for the admin (backend), and 1 for the API.
Use the V2 API. Spree 4 is aiming to have a new, revamped API that follows the JSON API spec and fully Ember compatible. For more information, please see the JSON API spec. The Spree V2 API is located here.

Related

How to install ember activemodel-adapter

I'm using ember-rails with ember-source and ember-data-source. But somehow the activemodel-adapter is not included in either of the gems. Or I'm missing something. I also searched bower, and can't find any. The code seems to be at: https://github.com/emberjs/data/tree/master/packages/activemodel-adapter
But it also needs compile. I'm wondering if there is an easier way to use it.
You must explicitly load a recent version of Ember Data. For example, add a version to the ember-data-source gem in your Gemfile:
gem 'ember-data-source', '~> 1.0.0.beta.7'
The active model adapter is included with Ember Data. Assuming everything in your project is global you could use it for your entire application like so:
App.ApplicationAdapter = DS.ActiveModelAdapter;

How to create a page through a Ruby Gem?

I am trying to create a gem which will create a page for your rails site say example.com/data and this page will show certain statistics about current rails installation say version etc.
Now I have created the gem using
bundle gem my_gem
but little unsure how to create a page through lib/my_gem.rb, can someone guide me here ? Thanks
A way I've done it in the past was to make a mountable Rails engine and mount that into your routes configuration. Here's a railscast on it:
http://railscasts.com/episodes/277-mountable-engines

Is there an updated rails_sql_views gem for rails 3.2?

I need the functionality provided by the rails_sql_views gem. However it looks like the last commit for this gem was made in 2010. Has this project been outdated by a new project? I'd like to find an active gem to use to get this functionality.
http://activewarehouse.rubyforge.org/rails_sql_views/
http://rubygems.org/gems/rails_sql_views
After further research here is a Rails 3 candidate for similar functionality:
https://github.com/bradphelan/Active-Illusion
This is a gem of this blog post:
http://xtargets.com/2011/08/02/tableless-views-with-active-record/
However this solution doesn't seem to be very popular.
schema_plus gem has create_view method that seems compatible (although I'm not familiar with rails_sql_views).
barancw, I needed this gem for our product using Rails 3.2.5, so I forked the repo and updated the necessary pieces. This gem is great for improving the performance of our large database queries, as it reduces the need to load objects into memory. I combined this gem with another optimization: Rails - given an array of Users - how to get a output of just emails?
https://github.com/ryanlitalien/rails_sql_views
Original documentation: http://rubydoc.info/gems/rails_sql_views/0.8.0/frames/index
Please keep in mind the docs are a bit outdated ("require_gem" has been replaced with "gem" and add the gem to your Gemfile as well).

How to package a gem into a Rails app that I'm concurrently developing with the app?

I'm developing a Rails app. Cool.
I'm also having to develop a component as a Gem.
Basically, the Rails app use Omniauth to allow authentication from an OAuth2 service provider. However, NO strategy exist for this particular service provider, so I am writing one, and using my app to test it (they kind of need to be tested together). Unfortunately, Omniauth now REQUIRES strategies to be packaged as gems, and put into the Gemfile along with the omniauth gem.
So basically I'm wanting to put /my-new-strategy-gem with the strategy contents, IN my /myrailsapp folder, and then do gem "mystrategy" :as => "/myrailsapp", where inside /my-new-strategy-gem there is an actual gem, with gemfile, readme, etc.
The reason I'm asking here is that I tried this before, and Git would not recognize the /my-new-strategy-gem folder inside my main app folder, since it contains its own .git file and other info.
I've heard of making it a submodule, or ways that use the vender folder, and other things, so I'm wondering which approach works best in this situation.
Edit: The reason I wanted to do it this way, too, is so my coding partner who is helping with both, could clone a repo with both, all at once, and we could repackage the standalone strategy gem later.
You can use the :git attribute to point to the git repository for your gem.
http://gembundler.com/git.html
gem "my_strategy", :git => "git://github.com/rcd/my_strategy.git"
I believe you could also do this locally instead of on github.

How can I create a rubygem and test it in a rails application at the same time?

I want to learn how to create a rubygem with a generator etc.
When I create a gem, do I create a separate project?
The reason being, since it will have generators and hook into the lifecycle of a Rails 3 application, I want to create a test rails 3 application at the same time to see how things are working etc.
Can someone outline what I should do to do this?
For example, I'm using git, so what I want to do is, when I run a generator for my gem and it doesn't do what I want, I can then easily rollback to the previous version using git.
This will be a simple gem, just trying to get a feel for things and how I can hook into various parts of rails etc.
Use bundler to create the new Gem with the following command:
bundle gem foogem
Then go to the Gemfile of the application you're going to use and add something like the following:
gem 'foogem', :path =>'/path/to/foogem'
In this way you can easily test your gem inside your rails project.

Resources