Thanks again to Oleg for pointing me towards ActiveResource.
I've been playing with it for a few days and it's working fairly well.
The one thing I don't have working yet is associations.
And from my googling around, it's not the easiest thing to get going.
I ghanged my "show" action in my raids controller to be:
def show
@raid = Raid.find(params[:id])
respond_to do |format|
format.html
format.json { render :json => @raid }
format.xml { render :xml => @raid.to_xml(:include => :players) }
end
end
I thought the embedded xml that would give me my list of players as part of
my ActiveResource model on the client side (similar to the way ActiveRecord
does), but unfortunately it doesn't.
It gets retrieved, but not as part of its "attributes".
I've also updated my routes.rb file with:
resources :players do
collection do
get :raids
end
end
and
resources :raids do
collection do
get :players
end
end
But these end up with URLs like /raids/players/1.xml. I'd much rather have
it be /raids/1/players, so I can then extend it to /raids/1/players/2, etc.
I can do that by defining routes like:
root :to => "raids#players
resources :raids do
resources :players
end
end
But that doesn't seem as "clean" as the first syntax.
I can see that I'm getting somewhere, and by adding more actions to my
controllers I'll be able to retrieve and generate the data relationships I
need on the server.
But it's starting to feel very "hacky". Is there a "rails" way of handling
relationships (retrieving and updating) with ActiveResource that is cleaner
than that?
Cheers,
--
Craig Read
@Catharz
https://github.com/Catharz
http://stackoverflow.com/users/158893/catharz
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.