remiprev/her — pull request #20 by jmlacroix (2012-07-29 03:27:31+00:00)
Title: Feature fix path

This patch removes the '/' prefix from the default paths.

When using an URL that is not a subdomain (e.g. http://localhost:4567/api/), Her does not find the resources without a custom path having no slash at the beginning.

Here is a sample app with a Sinatra api showing the problem:

*api.rb*

```ruby
require 'sinatra'

get "/users/:id" do
'{"key":"users without api"}'
end

get "/api/users/:id" do
'{"key":"users with api"}'
end
```

*app.rb*

```ruby
require 'her'

# Initialize API
Her::API.setup :url => "http://localhost:4567/api/" do |connection|
connection.use Faraday::Request::UrlEncoded
connection.use Her::Middleware::DefaultParseJSON
connection.use Faraday::Adapter::NetHttp
end

# Define classes
class User
include Her::Model
end

class Owner
include Her::Model
collection_path "users"
end

class ForceOwner
include Her::Model
collection_path "/users"
end

p User.find("jml").key
p Owner.find("jml").key
p ForceOwner.find("jml").key
```

bundle exec ruby api.rb
bundle exec ruby app.rb

Results:

users without api
users with api
users without api

Expected results:

users with api
users with api
users without api