Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

her and (Rails) shallow routes #170

Open
joost opened this issue Aug 21, 2013 · 1 comment
Open

her and (Rails) shallow routes #170

joost opened this issue Aug 21, 2013 · 1 comment

Comments

@joost
Copy link

joost commented Aug 21, 2013

I'm having an JSON API with endpoints like:
POST /contacts/1/tasks to create a Task for a Contact.

Her is setup like:

class ApiModel
  include Her::Model
  include_root_in_json true
  parse_root_in_json false
end

class Contact < ApiModel
  has_many :tasks
end

class Task < ApiModel
  belongs_to :contact
end

However when I try to do:

  Contact.find(1).tasks.create(:some_attributes => 1)

It POSTs to /tasks instead of /contacts/1/tasks (in contrast with what the documentation says).

Any idea what I'm doing wrong here? or any way to make this work with shallow routes (see: http://edgeguides.rubyonrails.org/routing.html#shallow-nesting)?
This would mean:

  • POST (create) would go to /contacts/1/tasks and
  • PUT (update) would need to go to /tasks/:id
@ak47
Copy link

ak47 commented Oct 1, 2014

I suspect you need need a collection_path in Task like " /contacts/:contact_id/tasks"

but the larger issue of shallow routes is my new thorn

"Her" seems to have no knowledge of this concept

update:
this seems to work
https://github.com/remiprev/her/blob/4824f6f18e4de091fede948cf362728c851f3654/lib/her/model/paths.rb#L80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants