Github: cloning an older version of an Rails gem - ruby-on-rails

There's a Rails forum gem I like called Forem https://github.com/radar/forem However, the gem author made some changes to it that negatively impact my intended use. He added a moderation tool, whereby all new/unapproved users need their first post approved before it's displayed to the forum. This essentially mean that a moderator needs to be present all the time or the forum will have a hard time get going. This is a recent addition to the app.
Since github is version control, I'm wondering if there's a way to clone or use (I just want to use it, not modify it) an older version of the gem so I can use a version before the moderation was added.
Thanks if you can help.

You have some options (all goes into Gemfile):
gem 'forem', github: 'radar/forem', ref: 'ref that you want'
or
gem 'forem', github: 'radar/forem', tag: 'tag that you want'
or
gem 'forem', github: 'radar/forem', branch: 'branch that you want'
All of it is described in Gemfile docs

Related

Is it better practice to specify a Rails version or branch in a Gemfile?

I'm presently using
gem 'rails', '~> 5.0.0'
in my Gemfile.
I just learned of a different way to specify a Rails branch, which is:
gem 'rails', github: "rails/rails", branch: '5-0-stable'
Is there a best practice to include Rails in a Gemfile? Why would you use one way over the other?
gem 'rails', '~> 5.0.0'
Uses what is called pessimistic versioning. The so called squiggly arrow means that it will use any new minor version in 5.0.X this means that you still get bugfixes but can be pretty sure the library won't suddenly change on you.
~> 5.0.0 is equivalent to >= 5.0.0 <5.1.
Linking a gem directly to a github repo is only really a good idea if you want to be on the bleeding edge or if an major issue or incompatibility exists in the latest release but is fixed in the master or another branch/tag. Another common case is where you need to fork a gem.
Often the case is that you want to use gem A, but the latest release of gem B is incompatible with A which often happens right after a major version is released.
To link all your gems directly to their master branches would be very trying for your sanity. Bundler can't actually resolve the versions there so will be no help for doing dependency resolution.
There's no best practice that I know of.
The stable branch of rails changes constantly, it just tries to have no bugs. Using such a branch might be a good idea if you know that you want your app to target the next version of Rails.
The gem version from rubygems.org is probably the 'best practice' now that I think about it. You can guarantee that the Rails codebase won't change out under you.
No harm in trying the github approach for a few weeks if only to learn the hard way!
Good luck

How to customize spree commerce?

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.

Which version of gem to use in semantic versioning?

Lets say you're using the Devise gem. Which version of the following should you use in your Gemfile:
'devise', '~> 3.5.1'
OR
'devise', '~> 3.5'
What are the pros and cons of using one over the other?
According to RubyGems:
PATCH 0.0.x level changes for implementation level detail changes,
such as small bug fixes
MINOR 0.x.0 level changes for any backwards compatible API changes,
such as new functionality/features
MAJOR x.0.0 level changes for backwards incompatible API changes, such
as changes that will break existing users code if they update
Wouldn't then it make sense to use 'devise', '~> 3.5' as those will get small bug fixes once bundle update is ran?
I think that you should use the full version number in Rails applications (or at least include your Gemfile.lock), and the other minor version number in libraries / rails engines.
I'm interpreting Gem Versioning and Bundler: Doing it Right by Yehuda Katz here. I might be wrong, but I'm doing it and works well so far.

how to require different gems with the same name?

I am interested in making an application that requires me to require a gmail gem for ruby.
Right now there are 2 gems:
https://github.com/dcparker/ruby-gmail
https://github.com/nu7hatch/gmail
Both gems have the same require name, ie: gmail
The second one is much clear but there is a problem with one of its method. This method works well in the first gem (link). So I was thinking maybe I could require the first one for just that method. Is it possible to do so, how?
As others answers and comments have said, you cannot simply require both gems as they are.
However, given that both are hosted on GitHub, you could fork one of them and rename the offending classes. So long as your renaming is consistent within the gem you could use your fork within your Gemfile
Of course, you wouldn't be easily able to rebase changes onto your fork easily but if you really must use both gems this might be a compromise that you are happy with.
You could add the following to your Gemfile:
gem 'gmail', :git => "git://github.com/dcparker/ruby-gmail", :branch => "master"
gem 'gmail', :git => "git://github.com/nu7hatch/gmail", :branch => "master"

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).

Resources