if defined?(ActionController) and defined?(ActionController::Base) - ruby-on-rails

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.

Related

Rails: Act_as_taggable_on vs. Rocket_tag

Looks like Act_as_taggable_on is the more established gem, but Rocket_tag is the newer and hotter one.
Which one would you recommend, and why?
Most of the posts I found that compared Rails tagging were fairly outdated, and I was wondering if anyone knew something about Rocket_tag (not much info on it out there).
I used both.
I am very happy with act_as_taggable, but for Rails 3.1 I switched to rocket_tag.
On every project that is in rails <3.1 act_as_taggable.
Sorry, I do not have any oline resources, just my own opinion.
I'm the author of rocket_tag so I'm a bit biased. The reason I wrote rocket_tag was that I found the code for the other taggable gems to be messy and unreadable and thus hard to extend and play with. I generally use Ernie Millers excelent Squeel GEM for writing and composing database queries. Squeel is a super clean and powerful ruby DSL for putting together SQL.
If you have a need for some custom tagging query then I suggest taking a look at how rocket_tag is put together and trying to roll your own tagging analysis method.

Ruby on Rails 3.1 Blog Engines

I see a lot of people asking about Blog Engines, but most of the questions & answers are rather old. Or if they aren't old most of the projects are old. I'm wondering if anyone knows of any Blog Engines that currently support Rails 3.1 or are at least being actively developed to support Rails 3.1.
I would also be interested in seeing any sample applications or blog posts written for Rails 3.1 Blogs. I am going to be adding a blog to one of my websites, and would prefer to simply use a Rails Engine or sample code if there are any good ones out there. I hate reinventing the wheel. Looking for something simple, and not too opinionated so I can modify easily to suit my own needs.
you might want to check out Refinery http://refinerycms.com/engines
doesn't look like they are 3.1 yet, but probably soon
https://github.com/resolve/refinerycms-blog
Your best bet would probably be to use Typo.
Typo is currently using rails 3.0.9. Rails 3.1.0 is still a release candidate so I don't know of any blogging apps using it right now. If you must use rails 3.1.0 then you may have luck grabbing the gem for 3.1.0.rc4 (the newest version) and using typo anyway. Chances are everything will still work.
Hope this helps.
Perhaps Enki is a good fit, currently at Rails 3.0 but there is a github branch with Rails 3.1 support.
http://www.enkiblog.com/
Interestingly BrowserCMS was recently made to be a mountable engine: https://github.com/browsermedia/browsercms/commit/6098699fed2e3dbd65815ac3a5ce0dd6acc103d2
Seem to have a bit of time and experience behind them. More akin to Concrete5 with an inline front end / in context editing facility for users, which can be a real plus.
Im looking into this now and Im getting to conclusion that the best way to do this would be mounting a rack-app(like sinatra) into your rails app, there's various basic sinatra blogs in github to start or copy, not to mention this is fully customizable and I guess very light-weight.. engines will likely have dependencies and may also break when updating gems, a rack app won`t
I wasn't able to find any satisfying solution with engines
other stuff I found:
mounting a rails app inside a rails app: http://blog.dynamic50.com/2010/02/22/rails-3-0-mount-multiple-apps-as-engines/ feels a bit weird(heavy?), but you could mount a fully featured app like enki...
http://planscope.io/blog/2012/03/08/mounting-a-blog-within-a-rails-3-application/ this blogpost talks about using Toto, it seems pretty nice, easy and simple... but the project is not being maintained and it doesn't seem to be able to support a lot of features...
I dunno about using git to post, it makes it really simple but I dunno if I'd like having non-code stuff in my commits
Monologue https://github.com/jipiboily/monologue . From their web:
It is a barebone blog engine for Rails. It is built as a Rails engine and with a focus on keeping very few dependencies to ease it's use in your project. You can also use monologue-markdown which will replace the default editor with a simple Markdown editor.
Seems like pretty active development also.

Is Rails 3 modular like Merb and Ramaze

Will Rails 3 be a modular framework like Merb or Ramaze?
By this I mean, can we use any persistence framework (DataMapper or Sequel) and jQuery in Rails 3 application (via the command line for example)?
Or the default stack (ActiveRecord, Prototype) is still enforced?
(Sorry, I'm pretty new to Ruby/Rails community).
Thanks.
Rails 3 is much more modular than previous versions. Although it still defaults to ActiveRecord and Prototype, it has an ActiveModel API which means that ActiveRecord can be swapped out for a compatible ORM that implements the API.
Rails 3 also embraces the principles of Unobtrusive JavaScript and to this end the view helpers no longer output inline JavaScript mixed up with HTML. Instead, HTML5 data attributes are used and there are Prototype and jQuery "drivers" for hooking into those and adding behaviour to elements.
The whole ActionController stack is also much more modular enabling you to cherry pick just the parts you need and the common (non-HTTP specific) controller functionality is now shared by ActionMailer too.
Rails merged with Merb in late 2008 and the result is Rails 3
http://yehudakatz.com/2008/12/23/rails-and-merb-merge/
http://weblog.rubyonrails.org/2008/12/23/merb-gets-merged-into-rails-3

Pattern to model wiki-type functionality

Is there a pattern or a gem (Ruby on rails) for modeling the wiki-like behaviour of a StackOverflow like web site?
I'm working on Ruby-on-Rails project so a gem or something in RoR would be appreciated but a well defined pattern is just as good.
Thanks
Did you try act_as_versioned? It is available as a gem, and adds simple versioning to any ActiveRecord model.
If you need more features, act_as_revisable might be interesting. According to the link, it adds the following features on top of act_as_versioned:
Pervasive Callbacks
Branching and Changesets
Deletes can be stored as a revision
Explicit is better than implicit
All data for a model is stored in one table
Wrapping up, requirements and installing

All I need is ActiveRecord and ActiveMailer, should I use Rails/Merb?

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.

Resources