Comments (6)
Hmm I see, yeah there should be a way to do that. Another way it could work is along the lines of
belongs_to :event
collection_path event_path + "/photos/:id"
I'd welcome a PR for either, if you're interested?
as a workaround for now, you can also define a function event_id
and it'll be used in the URL:
def event_id
self.event.id
end
from maglev.
I'll take a stab at it and get back to you with a PR :)
from maglev.
@clayallsopp so you're saying that added def event_id
would make my collection_path
and member_path
being /events/:event_id/photos
and /events/:event_id/photos/:id
work? I can't seem to get that working either..
from maglev.
I can get it working if i manually pass in the params in the find or find_all methods, but I can't by just defining the method in the model
from maglev.
Ahh I see, nevermind, I didn't totally think through the example, sorry!
What should work is this:
class Event < Maglev::Model
remote_attributes :id, :name
has_many :photos,
collection_path: "/events/:id/photos",
member_path: "/events/:event_id/photos/:id"
def event_id
self.id
end
end
event = Event.new(...)
event.photos.find_all do |photos|
end
event.photos.find(13) do |photo|
end
The facebook example does something similar: https://github.com/clayallsopp/maglev/blob/master/examples/FacebookGraph/app/models/user.rb
from maglev.
Never got to continue working on this one. Moved to San Francisco recently, and have been tied up in getting settled. I do plan on implementing nested collection paths, though
And thanks your your reply!
from maglev.
Related Issues (11)
- name change HOT 3
- Suggestion: change order of block params for remote_find_all HOT 1
- more examples from remote_model
- Undeclared gemspec dependency on formotion
- undefined method force_remote_relationship_syntax HOT 1
- question: example of how to set authentication HOT 3
- Load JSON from file HOT 2
- git://github.com/clayallsopp/maglev.git (at master) is not checked out. Please run `bundle install` HOT 4
- Will some kind of persistence be added to the gem? HOT 1
- uninitialized constant YAML (NameError) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maglev.