Which version of gem to use in semantic versioning? - ruby-on-rails

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.

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

Conditionally require gems in Gemfile based on Rails or Sinatra framework?

I am writing a gem that can be used with both Sinatra and Rails, however, the gem dependencies are different based on which framework the developer is using the gem on.
If it's a rails app, we need 'sass-rails' and 'coffee-rails'
If it's a sinatra app, we need 'sass' and 'coffee-script'
Ideally bundler would just install the necessary gems based on which framework this gem is being loaded into, but I can't seem to figure out how to conditionally specify dependencies.
Any suggestions would be much appreciated.
I would suggest you not to do that. It would be hackish and unreliable.
What you can do however is divide and conquer! Build a generic version of your gem that is framework agnostic and only handles the logic, let's call it yourgem-core, then you can build two other gems based on that first one, called yourgem-rails and yourgems-sinatra.
It's much better, only logic and logic test in yourgem-core, only rails integration tests in yourgem-rails, only sinatra integration tests in yourgem-sinatra
You can use :group option in bundler.
Reference: http://bundler.io/v1.5/groups.html

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

Github: cloning an older version of an Rails gem

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

Ruby On Rails: suggested gems / development stack

I'm new to RoR development and I'm searching for suggestion for finding best community gems.
E.g. for authentication/authorization? Is devise a good component? https://github.com/plataformatec/devise
Is there any gem for produce a richer gui in views with easy?
In few words, an experienced RoR developer what gems he installs after creating a new app?
Regards,
Giacomo
To answer the question, Ruby Toolbox is a great resource for finding Ruby/Rails projects (both new and old) as well as comparing the relative popularity of gems providing similar solutions. While the active development culture behind Ruby is empowering for developers accustomed to reading and writing Ruby, I think many newer developers get overwhelmed with all the options.
With that in mind, for someone who is just beginning Ruby/Rails development, I'd suggest either rolling your own authorization/authentication system or following a tutorial that explains the process. You can find a great tutorial explaining the basic structure of a User model including authentication in Michael Hartl's Rails Tutorial
Likewise, understanding that Rails Views can be as simple as combining regular, old HTML, CSS, and Javascript with some Ruby variables is valuable without depending on the magic of something like Bootstrap.
This is always basic in nearly all my apps.
gem 'devise'
gem "friendly_id", "~> 4.0.1"
gem 'omniauth-facebook'
gem "devise_mailchimp"
gem 'twitter-bootstrap-rails'
gem 'dragonfly', '~>0.9.11'
gem 'will_paginate'
gem 'will_paginate-bootstrap'
gem "mysql2", "~> 0.3.11"
gem 'thin'
and more. You can also visit http://railscasts.com/ you will get more ideas there.
Yes devise is very good gem with a lots of options and flexible authentications .
see this https://github.com/plataformatec/devise/wiki/Example-Applications
For gui in views you can use bootstrap twitter gem. It is easy and you can quickly build your view.
The gem installed by developers is depend on their need. there are more tah 1300 gem available right now...
Keep coding.
What helped me a lot was viewing a bunch of Railcasts. You'll get a good overview of gems you might want to use.
You can check this rails style guides from bbatsov, it's a community-driven guide, there are many practices that people used every day.
Here is my gemfile
you can also look into ruby-toolbox

Resources