I'm starting work on a project using Rails, but I'm waiting for the 3rd edition of the pragmatic rails book to come out before I purchase a book.
Anyway, my question is a bit more pointed than how do I get started...
What are some of the must have gems that everyone uses?
I need basic authentication, so I have the restful authentication gem, but beyond that, I don't know what I don't know. Is there a run down of this information somewhere? Some basic setup that 99% of the people start with when starting a new rails application?
Thanks in advance.
The gems and plugins that I tend to use on most of my projects are:
Restful Authentication -- For authentication
Will Paginate -- For pagination
Attachment Fu -- For image and file attachments
RedCloth -- For textile rendering
Capistrano -- For deployment
For pagination, will_paginate.
This is very, very subjective because it all depends on what your application does! However, I've just had a look at the Gems I have installed and the one that absolutely does leap out as mandatory is Capistrano.
BTW Restful Authentication is a Rails plugin not a Gem.
HAML is a must have. You'll never think of HTML in the same way again -- No more tag soup.
sudo gem install haml
sudo gem install ZenTest
rspec on rails
How can nobody have mentioned andand yet? It's the best thing since ||=
The only gems you need are:
Rails
Rake
If you "gem install rails" you'll get everything you need for Rails. You only need gems when you need them, so it's not worth worrying about before then.
EDIT: Actually there are a couple more you'll probably need:
mysql - or whatever Ruby database driver you need
mongrel - you don't necessarily need this until production, but it's nice to use in dev/test too
ZenTest - I use this mainly for "autotest" so that my tests run in a console window whenever my source files change
There could be many other gems that help you but we'd need more info from you to know if they're applicable, eg:
Web scraping (hpricot)
CSV (fastercsv)
Amazon S3 support (aws-s3)
Image manipulation (rmagick)
Graphing (gruff) - I use this as a plugin
Role-based security (role_requirement) - This one is a plugin too
mini_magick instead of rmagick.
Might want to keep an eye on: http://rubygems.org/ - you can see some interesting stats there re: most downloaded, most active, etc...
Also interesting and somewhat telling: https://github.com/languages/Ruby
This is a old thread but I thought I'll refine the list with what I believe to be must have gems at this point in time:
RSpec or Shoulda - tools for BDD/testing
factory_girl - fixture replacement
will_paginate - simple pagination
paperclip - image uploading/attachment
CanCan - authorization
Authlogic - authentication
HAML - templating engine
Related
I have a nice set of fixtures that I use for testing. When a request test fails it is handy to run the app interactively with the test fixtures loaded. But if I run the full server with -e test I get all kinds of crazy errors, probably having to do with the pipeline.
-- edit --
When I visit the home page I get this in the browser:
I say it's crazy, because I don't understand it :) In particular, I am using twitter-bootstrap and I am unclear about sass/scss/css work with Twitter Bootstrap + Rails so it's highly likely that I have some detail wrong in how I am using them together (or that the gem twitter-bootstrap-rails has some bug.)
Ah, much better question :-).
The twitter-bootstrap-rails gem uses LESS, which is similar to SASS in what it does, but not the same. SASS is the default for Rails, and a good choice. If you want to use SASS, (and based on the error, it appears you are), then use the Bootstrap SASS gem instead, linked here. It may be possible to use both LESS and SASS together, but that seems like a Bad Idea to me.
Check out Ryan Bates' excellent RailsCast which covers using Twitter Bootstrap in Rails. It covers both alternatives. And then fork over the $9 to get Pro access to his continued RailsCast with more details.
I just discovered the ruby-on-rails-gems tag (as opposed to the tags rubygems, gem, bundler, and ruby-on-rails-plugins).
Is there such a thing as a "Ruby on Rails gem", as opposed to an ordinary Ruby gem, apart from gems that merely have Rails or one of its components listed as a dependency?
It is a bad tag, it seems like it is mostly used by newbies, and it is usually paired with rubygems (which makes sense). Going through and removing the tags, only 64 questions, so it shouldn't take that long.
EDIT
Done. Not sure how SO works with this, but it doesn't seem to come in up autocomplete anymore. Some questions were literally tagged ruby-on-rails ruby-on-rails-3 ruby ruby-on-rails-gems ruby-on-rails-plugins. We need to evangelize the DRY principal when tagging SO posts :)
No, not that i am aware of. There is a rails gem which is basically Rails, aka Ruby on Rails.
Gems are packages of Ruby code. Rails itself is a gem, and so is ActiveRecord, ActiveResource, etc etc.
I presume the tag is referring to gems that are compatible with Rails, such as Devise or acts_as_paranoid.
I guess it could be interpreted as "gems that are specifically made to work with Rails". There's plenty of gems which wouldn't work outside of a Rails app. I don't think it's a very useful tag though.
What is the best practice when creating a rails project
1 - is it good to use ruby gems
2 - or is it good to use ruby plugins (as almost all the gems has their plugin versions)
and what are the strengths and weaknesses of eachoption
consider we are creating the rails project with rails 2.x.x or rails 3
thanks in advance
cheers,
sameera
I think you should have to go with gems if possible. You will have a rich framework with slim applications. If you use a lot of plugins your application will be too heavy. I'm talking from experience. I have an application with a lot of plugins in it and it is hell slow.
I prefer to use gems because then I can manage them with Bundler and it will install the necessary dependencies for me. It will also cache gems, which solves deployment issues.
Also, it isn't possible to use only plugins, there are always gem dependencies, and I'd rather use just one mechanism, so that's another point for gems.
I think that plugins are slowly turning into gems and Rails 3 is moving further in that direction.
In my case, I use gems whenever I can but I do use plugins when I don't have access to gems on the host.
For example, Heroku doesn't have all the gems and neither does Media Temple. Since plugins are imported with the project, you can get away with it :)
As a Rails developer I feel a bit stupid asking this question but hopefully I will learn something new and someone can put me out of my misery! In my rails applications I use (other peoples) gems all the time, I also use plugins from the community or my own.
I understand the benefits of use gems over plugins as they are version-able, segmented, system wide, easier to manage and share etc etc but I don't really know how to go about making a gem for my rails apps!?
Do you always start with a plugin and convert it to a gem, I've seen the words 'package it as Gem'. Also the gem I'm thinking of building would be no good in a normal ruby program, it's only useful to rails apps. I'm not even sure if the semantics of that make sense, 'RubyGem' that will only work in a rails application!?
I would like to create a gem (if that's what I should use?) for a discrete piece of functionality for my rails apps. It will need to add a database migration, new routes and provide controllers and views or useful view helpers. I'm know I can achieve this via a plug-in but would just like to know how/why to do it as a 'Ruby Gem'?
To avoid the risk of Over-engineering, I usually start with the feature I need directly into the application. Then, as soon as I need to use the same feature into another project, I check whether it is worth to extract it into a plugin or even a separate application providing an API.
Plugins and Gems are often interchangeable. Gems provides several significant advantages in terms of reusability and maintainability.
On the other side, there are some specific known issue. For instance, a Rails app actually can't load rake tasks defined into a plugin packaged as a Gem.
Almost every Rails plugin can be packaged as a Gem.
For instance, take my tabs_on_rails plugin.
You can install it as a Gem specifying the dependency on environment.rb. Or you can use script/plugin install command as you would expect.
If you want to achieve the same result, make sure to follow the standard Gem layout and provide the init.rb initialization script required by Rails.
Also, you might want to create an install.rb and uninstall.rb file to include the post-install and post-uninstall hooks when the plugin is installed as a standard Rails plugin.
Last but not least, if you package a plugin as Gem you can reuse it in non-Rails projects and provide Rails-specific initializations using the init.rb file. Non-Rails applications will simply ignore it.
If you want to make a plugin for Rails, https://peepcode.com/products/rails-2-plugin-patterns gives you a good start. After that, make the plugin into a gem.
To make a gem, this resource http://railscasts.com/episodes/183-gemcutter-jeweler will be helpful.
As of 2013 you'll want to use Bundler and the following tutorials:
#245 New Gem with Bundler -
RailsCasts
Make your own gem - RubyGems
Guides
Take a look at Jeweler. Jeweler gives you a set of rake tasks to make gem versioning and building very easy.
I have developed a simple library in Ruby and need to use this in several Rails applications (some of which are not built yet). What is the best way to easily add this Ruby library to several Rails applications as and when required? Our team is running Ubuntu and our repository is Mercurial.
Should I use a...
Rails plugin? This would be my first
choice but it appears not to support
Mercurial??
Ruby Gem?
Custom Rake script?
Other options??
Any pointers would be much appreciated!
Ruby already has an established mechanism for code sharing i.e. RubyGems. Jeweler makes Gem creation easy. I'd recommend that you check it out.
Make a gem or a plugin. Gems are better in my opinion, easier to manage.
My rule of thumb:
If it doesn't depend on rails, make it a gem.
If it depends on rails, make it a plugin.
Make a Rails plugin. It doesn't "support" Mercurial in the sense that you can't do script/plugin install $REPO_URL and have it work automatically, but if it's for your own use, then you won't miss that feature.