Today I ran into a couple of issues/gotchas while attempting to split out an Ember.js-based sub-project into a Rails engine. Here is how I was eventually able to get things going. This is accurate as of Rails 4.0.1 and ember-rails 0.14.0.
Create the Engine
rails plugin new --mountable vendor/engines/my_sub_project
Add Ember-Rails as a dependency
Your newly created engine should have a gemspec file in it, named something like my_sub_project.gemspec. Add the following dependencies to the spec:
s.add_dependency "ember-source", "1.1.2"
You will also need to update each of the configuration options that are tagged with
TODO before proceeding.
You should now be able to call
bundle install to install the Ember.js dependencies.
Bootstrap with Ember.js
Next, you should be able to execute
bundle exec rails generate ember:bootstrap to bootstrap the engine with the Ember.js directory structure and basic files.
Except there is a bug in the current version of ember-rails that I have submitted a patch for, here. Until that has been merged, this command will error out. Feel free to use my branch to get going if it has not been merged by the time you read this.
It is important that you run the rails command with bundler, otherwise the generator will not be found.
That should be it!
After banging my head against the wall for awhile trying to get an Ajax user invite form to work with Devise::Invitable, I finally stumbled upon the solution which was not overly apparent at the time (it is in hindsight, of course).
By default, Devise only responds to HTML requests and you don’t really want to add JSON as a supported navigational format since you want authentication errors to be returned with a 401 status for API formats. However, if you override the default Devise::InvitationsController, you simply need to add JSON to the list of supported response formats:
class Users::InvitationsController < Devise::InvitationsController respond_to :html, :json end
You should read the section Configuring Controllers in the DeviseInvitable README to fully configure your custom controller.
I’ve created a widget to pull traffic data from the excellent Gauges service by GitHub and display it in your Status Board. If you haven’t heard of Status Board yet, it’s a dashboard for showing all sorts of data on your iPad (or big screen TV) developed by Panic, Inc.
While working on creating the distribution script for packaging the Singly iOS SDK, I ran into a number of issues trying to automatically assign a custom icon to one of the distributed folders. I searched and found a myriad of solutions, but they all suffered from one or more problems:
- the embedded icon was not high-resolution, so it looked terrible when scaled,
- or you could not use an ICNS bundle directly without extracting an image from it,
- or most of the command examples did not function properly on Mountain Lion.
So after much trial and error, I finally came up with a solution that would address all of the above issues. The following assumes that you already have an ICNS bundle containing your icon at various resolutions.
Step 1 — Create Folder w/Custom Icon
The first thing we need to do is create a temporary folder in Finder and set our ICNS bundle as its icon via Finder’s Inspector:
- Create a new folder (for this example we’ll use “tempfolder” as the name) in Finder.
- Right-click on the folder and select “Get Info” from the context menu.
- Drag your icon file and drop it onto the standard blue folder icon at the top left of the Inspector window.
Step 2 — Extract the Icon Resource
Now that we have a folder with our custom icon set correctly, we will need to extract the resource fork containing our icon. Open the Terminal and execute the following command:
DeRez -only icns path/to/tempfolder/$'Icon\r' > MyIcon.rsrc
This will extract the properly formatted icon resource into a separate file that we will use later. You can now trash the temporary folder we created in step 1.
Step 3 — Apply the Icon Resource
Once we have the extracted resource file, we can apply it to any folder (or file) of our choosing at anytime from the command-line (or a script). This is useful if you need to automate the process of setting a custom icon on a generated folder, such as when you are packaging a new release.
To apply the custom icon to your folder, execute the following in Terminal (or from a script):
Rez -append path/to/MyIcon.rsrc -o path/to/folder/$'Icon\r'
SetFile -a C path/to/folder
Be sure to keep your extracted resource file around so you can use it in the future.