Some modifications to get code examples working with Rails 3 gems

28 views
Skip to first unread message

ed_ruder

unread,
Sep 5, 2010, 12:09:35 AM9/5/10
to Service Oriented Design With Ruby
I just bought this book and I'm working through the examples. I have
Rails 3.0.0 installed, and the gems I have are newer than what the
example code works with. Here are some things I needed to do to get
them working. I will add to this discussion as I figure out more
changes.

1. In The Ruby Tool Set:

gem install sqlite3-ruby -v 1.2.5
gem install rack-test

2. In The User Service Implementation:

a. The Rakefile file:

require 'active_record' # 'activerecord' has been deprecated
require 'logger'

b. Migrate the database:

rake db:migrate SINATRA_ENV=test

c. Correct the spec to properly access the user's attributes:

All references to attributes need to be attributes["user"]. E.g.:

attributes["user"]["name"].should == "paul"

ed_ruder

unread,
Sep 5, 2010, 12:18:59 AM9/5/10
to Service Oriented Design With Ruby
Re: 2.c.:

I decided that this approach was a little cleaner--attributes remains
the attributes of the user:

attributes = JSON.parse(last_response.body)["user"]

ed_ruder

unread,
Sep 6, 2010, 2:38:11 AM9/6/10
to Service Oriented Design With Ruby
3. In Implementing the Client Library:

a. Correct client.rb to properly access the user's attributes. In
User.find_by_name:

if response.code == 200
JSON.parse(response.body)["user"]
elsif response.code == 404
nil
else
raise response.body
end

jdixon

unread,
Sep 11, 2010, 8:29:31 AM9/11/10
to Service Oriented Design With Ruby
Thanks for pointing out #1. As a Ruby noob, I've been beating my head
against the wall trying to figure out why "require 'rack/test'" would
fail even though the directory 'test' is clearly inside the rack gem
directory.

JWeldin

unread,
Sep 17, 2010, 2:01:15 PM9/17/10
to Service Oriented Design With Ruby
Am I glad that someone else has had the same issues I have had. I had
figured out the changes except for the attributes["user] part. It was
driving me bonkers. Thanks!

JWeldin

unread,
Sep 17, 2010, 2:17:29 PM9/17/10
to Service Oriented Design With Ruby
In service.rb I had to make the change:
#require 'models/user'
require File.expand_path(File.dirname(__FILE__) + '/models/user')

Did anyone else have an issue with require 'models/user'?

nateklaiber

unread,
Sep 24, 2010, 7:23:01 PM9/24/10
to Service Oriented Design With Ruby
I had the same issue as you did.

Dan

unread,
Oct 8, 2010, 10:55:39 PM10/8/10
to Service Oriented Design With Ruby
I had this issue as well. Thanks for pointing out the fix. I also
had the same problem in the spec class where it references the
service.rb file

The other fixes in this thread were also very helpful. Thank you all.

Another question... on page 11, the book says you can run the service
with this command: ruby service.rb -p 3000

I ran that command and I didn't get an error, but I also wasn't able
to view the service. The next command prompt comes up, not a server
or anything like that (something like WEBrick). Anyone have any idea
why this might be? I'm able to browse to http://localhost/ and that
works, but if I go to http://localhost:3000/ I get nothing after I run
that command.

Dan

unread,
Oct 8, 2010, 11:28:53 PM10/8/10
to Service Oriented Design With Ruby
I was able to get this working as well. Found the fix in this
article:

http://ruby.about.com/b/2010/09/08/sinatra-not-working-on-1-9-2.htm

Needed to add this line under the require statements, but before
everything else:

enable :run

On Oct 8, 9:55 pm, Dan <dan.dona...@comcast.net> wrote:
> I had this issue as well.  Thanks for pointing out the fix.  I also
> had the same problem in the spec class where it references the
> service.rb file
>
> The other fixes in this thread were also very helpful.  Thank you all.
>
> Another question... on page 11, the book says you can run the service
> with this command:  ruby service.rb -p 3000
>
> I ran that command and I didn't get an error, but I also wasn't able
> to view the service.  The next command prompt comes up, not a server
> or anything like that (something like WEBrick).  Anyone have any idea
> why this might be?  I'm able to browse tohttp://localhost/and that
> works, but if I go tohttp://localhost:3000/I get nothing after I run
Reply all
Reply to author
Forward
0 new messages