Railsgrammer

Author Archive

Never a fun error: Access-Control-Allow-Origin

by coffeencoke on Jan.19, 2012, under Development

If you are testing any javascript app against a web service and you run into the following error in your javascript console:

XMLHttpRequest cannot load http://localhost:3000/. Origin http://myapp.dev is not allowed by Access-Control-Allow-Origin.

In this context it means that the host your are making the request from does not have permission to access the requested resource (it also means a lot of other things).  After hunting you can do a at least 2 things:

1. Add the host to the access list by adding to the request header (http://enable-cors.org/)

2. Load the app using file:/// rather than the host.

Because I was writing this app as a native mobile app for iOS, Android, etc. I found out that PhoneGap loads the html files using the file:/// protocol.  So now, when I am developing on my computer, as long as I use the file:/// protocol, I have no problem with access to my API.

Leave a Comment :, , , , more...

Phone Gap Whitelist Rejection Error

by coffeencoke on Jan.19, 2012, under Development, Ruby on Rails, iOS

My mobile app continues. As I was testing my registration API through the iOS emulator I got the following error:

MyApp [97185:15603] ERROR whitelist rejection: url='http://localhost:3000'

After some quick google searching, I discovered that in order to make requests outside of the file system I had to add the host to the phone gap’s plist file. For my project this file is located at /MyApp/PhoneGap.plist. You can either edit this file with a text editor or edit it in Xcode. The end result for me to be able to hit localhost within the app looks like this:

<?xml version="1.0" encoding="UTF-8"?>
...
<key>ExternalHosts</key>
<array>
<string>localhost</string>
</array>
...

After I made that change, I restarted my app through Xcode and the app was able to hit the rails server.

Leave a Comment :, , , , , , more...

Cucumber and iOS – one step at a time

by coffeencoke on Nov.06, 2011, under iOS

I have begun writing my first iOS application.  I come from a ruby background and for the past 2 years I have written everything test first starting with cucumber scenarios all the way down to unit tests.  The problem with starting a brand new language for me is I wanted to dive straight in to writing the production code.

WRONG.

That would not be test driven and the very fact that I wanted to do that made me throw out my core principles of writing solid quality software.

So I started looking into how I could write Acceptance Tests or Integration tests to drive my development and ultimately drive my learning of how to write an iOS application.

After browsing for a bit I found iCuke which was quite out of date.  If you look at the github page for this app it has not been touched since June 30, 2010! So I browsed a bit more and found Frank which was updated a blazing 3 days ago!  Much better.

So, keep in mind that I have absolutely zero amount of knowledge on how to write an iOS application.  The tutorial for setting up Frank for an iOS application was point blank easy.  Follow the guide at this tutorial and you’ll be good to go.  There is also this video that steps through that guide so you can visually double check that you set it up correctly!

How great is that!?

So far I am very excited to work on this application, I was bummed thinking that I will not be able to apply my core principles of a software craftsman for a new language but having found Frank, I will be able to drive my learning by writing very high level test scenarios for what I want to learn.  One step at a time.

The only addition I made is because I am from a ruby development background I used rvm and bundler to manage the gem.  The instruction in the tutorial is to run the following:

$ sudo gem install frank-cucumber

To do it the current way.  Use bundler (view the bundler website or view some of my bundler articles on how to get running with bundler).  The quick addition I made is to add a file named .rvmrc at the project root with the following content:

rvm use 1.9.2@my_great_ios_app --create

create a file named Gemfile with the following content:

source :rubygems
gem ‘frank-cucumber’

open a new shell or cd out of the directory and back in to accept the rvmrc file

$ cd ..
$ cd -

Read and approve the instructions to accept the rvmrc file. Basically it will just create a gem set named my_great_ios_app within my ruby 1.9.2 installation. After that, install the gems:

$ bundle install

Now that this is completed, you will not have any other gems for this project except what it needs and you will not have any gems for any other project except for what those projects need. Excellent way to have multiple projects on multiple versions of ruby and still be able to manage the gems at the application level.

Keep checking in to see more articles on how I am learning how to write an iOS application.  If you have any comments, questions or suggestions, please drop me a comment or email.  I’d love to hear from you.

Leave a Comment :, , , , , , more...

Ruby Midwest Conf – Day 1 Part 1

by coffeencoke on Nov.04, 2011, under Ruby on Rails

So far the day has been filled with great pastries, excellent coffee, typically frustrated conference wifi, and fantastic talks about Ruby and craftsmanship.

The day started off with the why you should not use sudo, for most things. Your ruby development computer should be setup using a number of tools that should not be installed with sudo, simply because with most if the tools, they can’t. Your development environment should be isolated in your profile, one step deeper though; isolated in your project.

Use RVM .
Ro

RVM is a ruby version master (err, manager). It allows you to install multiple versions of Ruby, JRuby, Rubinius, etc. on the same computer. Further yet, it allows you to have completely separate gems for each project by using gemsets.

The Ruby Safari
Ola

Ola did a great job throwing out some technical intricacies which really pushed me to get to know my language more. As I develop using Ruby I use and reuse the same methods and classes. His talk has encouraged me to look into deeper implementation of Ruby and to ‘play’ with creative patterns.

One thing I particularly liked is commenting and writing Regular Expressions with group names. However, the big bang from his talk for me was requiring a fake library. I am constantly growing and learning (trying to) and one place I have been focusing on is speed of tests and design of tests, unit tests to be more specific. With rails, it is very difficult to write true unit specs that are blazing fast. More to come on this in future posts.

Leave a Comment :, , , , , more...

Mac Issue: AELWriter Permission denied

by coffeencoke on Feb.07, 2011, under Uncategorized

When I was inserting a new Product Serial Number for Adobe Aperture after migrating Aperture from another computer via that mac osx migration assistant.  Apperture will spin the dreadful spinning wheel of death and spit out this in the Console:

2/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter[1230]) posix_spawn("/usr/sbin/AELWriter", ...): Permission denied
2/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter[1230]) Exited with exit code: 1
2/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter) Throttling respawn: Will start in 2 seconds
2/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter[1230]) posix_spawn("/usr/sbin/AELWriter", ...): Permission denied2/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter[1230]) Exited with exit code: 12/6/11 9:19:24 PM com.apple.launchd[1] com.apple.launchd (com.apple.aelwriter) Throttling respawn: Will start in 2 seconds

The fix is found here:

Apple Support Fix

happy fixing.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...