I'm writing a Rails 4 app from scratch and I want it to be as independent as possible. For example, if I'm writing an authorization code, I don't want to use bcrypt gem.
So what are the absolute essential gems for Rails to work visually and technically?
As an example, I'd just like to create a simple scaffold user first_name last_name that I can see on my browser and make simple create, read, update, destroy operations from the browser.
The rails 4 app comes bundled with a lot of gems. Most of them are very good things to keep, but if you really care about it:
rails - That should be self explanatory.
sqlite3 - You need a database gem. Personally I use mysql, but it's totally up to you and the comparisons are beyond the scope of this question.
sass-rails - this is used in precompiling assets from stylesheets. Sass provides a lot of nice utilities, including the ability to nest CSS rules that make your stylesheets both more readable and maintainable, but if you don't want it, you don't need it.
uglifier - if you don't care about sending minified JS (as in you don't care about the size of your request responses) you can get rid of this. I definitely wouldn't recommend that though.
coffee-rails - if you don't want to use coffee script you can get rid of this.
jquery-rails - most modern sites use some kind of javascript library, be it jquery, prototype, angular, Node.js, or something else. It's up to you, but I would at least use something.
turbolinks - rails 4 by default uses javascript to load each page, which speeds up the page load time significantly. You need to read more here if you're going to get rid of this.
jbuilder - if you don't care about responding with jsons, you can get rid of this (definitely don't recommend)
sdoc - if you don't want documentation, you can remove it.
capistrano - this is for helping with deployment, and I would suggest using it.
Related
Its a code snippet from act_as_audited plugin 1.1.1 under rails/init.rb
Why is this code used? Any general explanation of it is welcomed.
if defined?(ActionController) and defined?(ActionController::Base)
acts_as_audited is intended to be usable with plain ActiveRecord. As you can use ActiveRecord outside of Rails, e.g. in a Sinatra app, it is helpful if a gem doesn't tie itself to Rails.
This is exactly what is happening here: the authors try to detect if they are running under Rails (or more specifically, if the app uses ActionController for routing which is part of Rails) to load additional Rails-specific functionality.
For apps not using ActionController (or Rails), the gem is thus still usable.
It seems that they have dropped this compatibility layer in later releases. This, the successor of acts_as_audited (called just audited) depends on Rails now.
I've done some reading about the various options for improving the speed of a rails site.
The following libraries seem promising:
pjax
turbolinks
cache_digests
However, it seems like they try to do many similar things.
Can/Should you use them in tandem? Are there problems that would arise in doing so?
Are there cases where one or the other is better than the rest? (And what are they?)
Is there something superior to all three I should check out instead?
I prefer pjax. It's easy to use and very fast. You just have to define a pjax-container which will be replaced every request.
Turbolinks instead does replace the whole body. I don't like that very much. But that's matter of taste. It will be part of Rails 4.
cache_digests is not something that can be compared with pjax or turbolinks.
cache_digests enhances Rails caching to allow for Russian-doll caching.
Turbolinks tends to be a bit more straightforward and doesn't require jquery.
Pjax is configurable but required jquery.
I'm trying to understand what the benefit is here; the only I can see is avoiding a rails bootstrap every time an email is received, but I imagine this is possible with ActionMailer as well with a bit of set up. Any help would be very useful.
Chris.
http://rubygems.org/gems/mailman
The benefit is to avoid the Rails overhead, and it provides some syntax sugar. Also to avoid having to write it yourself.
The fact is though that the underpinnings of the Mailman Micro-framework are essentially the same as ActionMailer the Mail gem. You can achieve the same results using ActionMailer or just Mail without the added dependencies. It just really depends on your use case, and how much you want to write yourself.
I am planning on using the Sanitize gem in a Rails project as a way of cleaning user-submitted HTML snippets. The gem source on Github includes a robust set of tests, though they are not included in the final gem. In my model tests, I want to again verify that the gem does what it should be doing and that my model only stores clean HTML. It seems like overkill to have to recreate all of the gem tests in my model test, and I would prefer to have my test just make sure that the model's before_save filter (which calls on the Sanitize gem) works. What is the best way to handle this?
On a side note, while researching this I came across the GemTester area of RubyGems, which looks really promising, but requires gem authors to opt-in each gem.
I don't know if this will be the answer you're looking for, but my general principle is to not write tests for third party libraries. Rather, write tests for your integration points with those libraries, or the code that you're writing on top of those libraries. I would include a test to perhaps make sure that the before_save filter is being called correctly and leave it at that.
I have a small web application that is currently running on Sinatra. It only has two pages so I don't really need controllers or many views. I have included ActiveRecord to interact with a database and ActiveMailer to send and receive mail.
Would it be worth it to use Rails, or Merb on a project as small as this? I find myself adding features that are included in Rails. I haven't had any experience with Merb before so I don't really know if that would be a suitable option. But from what I hear Merb may be the way to go on a project that only needs a few components.
Thanks.
No need to switch to Rails if your already running on Sinatra for a small project. You can use ActiveRecord and ActiveMailer outside of Rails.
Merb is merging with Rails for Rails version 3.0. As part of this process, the core Rails architecture is going to be "merbified" so as to be more easily configured to only use the particular components you need.
There may going to be a point as your application grows that you find yourself reinventing features that already exists, in this case I would consider switching frameworks.
Personally, I use Rails even for quite small projects. It means I have a single framework and deployment environment for everything that I work on.
I use Sinatra often for stuff much bigger than what you describe. What features of Rails do you find you are needing to add? If it's just stuff like 5.hours.ago and stuff, you could always: a) pull that part of the code out of activesupport and paste it into a 'common'/similar file in your project or b) just require activesupport and use it's features.