I'm using ember-rails with ember-source and ember-data-source. But somehow the activemodel-adapter is not included in either of the gems. Or I'm missing something. I also searched bower, and can't find any. The code seems to be at: https://github.com/emberjs/data/tree/master/packages/activemodel-adapter
But it also needs compile. I'm wondering if there is an easier way to use it.
You must explicitly load a recent version of Ember Data. For example, add a version to the ember-data-source gem in your Gemfile:
gem 'ember-data-source', '~> 1.0.0.beta.7'
The active model adapter is included with Ember Data. Assuming everything in your project is global you could use it for your entire application like so:
App.ApplicationAdapter = DS.ActiveModelAdapter;
Related
I've got some helper code (monkey patches) I tend to carry around from rails project to rails project via simply copying files or pasting code into the initializers folder.
I think a clean way to deploy different categories of my initalizer code would be to simply add gems to my project Gemfile that would do the equivalent of this for me. I'm not very skilled at creating gems or the deeper side of ruby on rails engineering so I just wanted to know if this were possible before I got started with it.
Yes, this is definitely possible. It should be probably enough to make a simple gem, put your monkey-patches there and require them in the gem entry point (e.g., if the gem is called foobar, then bundler will require lib/foobar.rb by default).
There is a guide on creating gems available in Bundler docs. In case you need to interact with Rails application configuration, you can take a look at Rails Engines.
I've been using Rails for a while and have always used gems in my gemfile, but I never really understood how the functionality of gems that I install actually become available. Say I use the has_permalinks gem (http://haspermalink.org/). It provides a .generate_permalink! method for my Model. Where does this method get defined? How come just I can use this method all of a sudden just by installing the gem? Is there some sort of include/require/load to initialize the gem's code so that it becomes accessible to the rest of the application? Also, where is this code stored when I install the gem?
I answered your questions separately, and out of order, but I think it actually might make it easier to understand the answers in this order.
Also, where is this code stored when I install the gem?
If you're using Bundler, you can do bundle show has_permalink and it will show you where that gem is installed. Here's an example of me doing it with the pg gem:
✗ bundle show pg
/Users/jasonswett/.rvm/gems/ruby-1.9.2-p320#jason/gems/pg-0.11.0
Where does this method get defined?
If you do the bundle show thing, it returns a path - the method is defined somewhere in there. (You can use grep -r 'def generate_permalink' /gem/path to find exactly where if you want.)
How come just I can use this method all of a sudden just by installing
the gem? Is there some sort of include/require/load to initialize the
gem's code so that it becomes accessible to the rest of the
application?
Look at this part of the doc about the Rails initialization process:
http://guides.rubyonrails.org/initialization.html#config-boot-rb
In a standard Rails application, there’s a Gemfile which declares all
dependencies of the application. config/boot.rb sets
ENV["BUNDLE_GEMFILE"] to the location of this file, then requires
Bundler and calls Bundler.setup which adds the dependencies of the
application (including all the Rails parts) to the load path, making
them available for the application to load.
It looks like, fairly early on in the process, Rails looks at your Gemfile and loads all your gems via Bundler. So there's your include.
I am using Ruby on Rails 3.2.2. I have implemented a Something plugin (it is almost a gem, but is not a gem) and all related files are in the lib/something directory.
What steps should I accomplish to "convert" the Something plugin to a Ruby gem?
How to use the new implemented Something gem in my application without to make it public (that is, without put that on a public server)?
http://guides.rubygems.org/make-your-own-gem/
Previous link covers that as well - gem install something-1.2.3.gem
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).
I'm working on creating my first Rails 3 engine and I'm currently getting the following error message
is a Railtie/Engine and cannot be installed as plugin (RuntimeError)
To give you a bit more background I'm not doing the Engine as a gem, but I've place the Engine files in the vendor/plugins folder. I know there is an issue with loading when in the plugins folder, but I'm not clear on how to solve the problem.
My rails/init.rb file in the Engine has the following code
require 'rails'
module RailsApp
module MyEngine
class Engine < Rails::Engine
config.after_initialize do
RailsApp::GameType.register do |game_type|
game_type.name = "TreasureIsland"
game_type.version = "0.1"
game_type.thumbnail = "teasure_island.jpg"
end
end
end
end
end
Suggestions?
I think I remember reading that Railties would not work in plugins directory, because they are intended to be loaded at a different point in the application boot process. I would recommend creating a gem using something like Jeweler, which does alot of the work for you. The purpose of the Railtie/Engine is to have a reusable component that can be included in multiple rails apps. Once you have a gem created, you can point to the local gem path within your Gemfile. This allows you to see changes in your engine code inside your rails app without having to build and reinstall the gem every time you make a change to the engine code. Of course you would want to point bundler to the installed gem in production. I would recommend putting it on github and using that URL in your Gemfile in production.
Bundler local gem example:
#Gemfile
gem "my_engine", :require => "my_engine", :path => "/my_engines/my_engine"
Check out the Modern Rubyist's website. He has a good series on creating Railties and Engines. There may have been some changes to Rails since this was written, but I think most of it is still relevant. It helped me out a good bit when I was learning how to write Engines with Rails 3.
http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/
http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/
http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/
http://www.themodestrubyist.com/2010/03/22/rails-3-plugins---part-4---more-on-generators/
John, I believe engines (which are typically gems) vs plugins (which live in vendor) are loaded at different points in the rails initialization process.
Engines actually have a bit more flexibility, they can hook deeper into rails. In addition, packaging as a gem has a lot of advantages: easier to share across apps, easier to maintain in a separate code repo, easier version control.
I'm creating my first rails engine right now and created a useful starting point and walk-through for getting started:
http://keithschacht.com/creating-a-rails-3-engine-plugin-gem/