Hello, I''m trying to write a piece of code that enables users to upload an avatar. The user code and the avatar code does work great, but now I want to associate the avatar with the user, which should also be reflected in the urls. I''ve read the B-Simple REST tutorial (http://www.b-simple.de/documents) which explains this process for one-to-many associations. But things are a little different for me, because I only want one avatar per user, I do not need an index action and the urls do look different. For example, I want /user/:user_id/avatar to show the user avatar, /user/:user_id/avatar;edit to change the avatar etc. Is there any way to achieve this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I''m still finding my way around RoR myself but isn''t what you want something like?: class User < ActiveRecord::Base has_one :Avatar, :foreign_key => "your_avatar_id_key", end class Avatar < ActiveRecord::Base belongs_to :User, :foreign_key => "you_user_id_key", end -- Regards Andrew On 03/03/07, rv dh <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > > I''m trying to write a piece of code that enables users to upload an > avatar. The user code and the avatar code does work great, but now I > want to associate the avatar with the user, which should also be > reflected in the urls. > > I''ve read the B-Simple REST tutorial (http://www.b-simple.de/documents) > which explains this process for one-to-many associations. But things are > a little different for me, because I only want one avatar per user, I do > not need an index action and the urls do look different. For example, I > want /user/:user_id/avatar to show the user avatar, > /user/:user_id/avatar;edit to change the avatar etc. > > Is there any way to achieve this? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello Andrew, thanks for your reply. Unfortunately this does not help me, because this is for the associations only. I need help for reflecting these associations in my REST enabled urls. Andrew Madu wrote:> Hi, > I''m still finding my way around RoR myself but isn''t what you want > something > like?: > > class User < ActiveRecord::Base > has_one :Avatar, :foreign_key => "your_avatar_id_key", > end > > class Avatar < ActiveRecord::Base > belongs_to :User, :foreign_key => "you_user_id_key", > end > > -- > Regards > > Andrew-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I''ve read the B-Simple REST tutorial (http://www.b-simple.de/documents) > which explains this process for one-to-many associations. But things are > a little different for me, because I only want one avatar per user, I do > not need an index action and the urls do look different. For example, I > want /user/:user_id/avatar to show the user avatar, > /user/:user_id/avatar;edit to change the avatar etc.map.resources :people do |people| people.resource :avatar end avatar_url(:person_id => person) # => /people/5/avatar edit_avatar_url(:person_id => person) # => /people/5/avatar;edit --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
on a similar note, what''s generally regarded as best practice for a REST-ful multi-lingual site, let''s say one which uses Globalize, where the language code has to be passed around in the URL (so that pages can be cached easily per language)? If the first part of the URL always holds the language code, e.g.: http://mysite.tld/en/..... http://mysite.tld/de/..... http://mysite.tld/es/..... How is this declared using resource/resources? An outer map.resource which contains all other route mappings? 3 mar 2007 kl. 17.45 skrev DHH:> >> I''ve read the B-Simple REST tutorial (http://www.b-simple.de/ >> documents) >> which explains this process for one-to-many associations. But >> things are >> a little different for me, because I only want one avatar per >> user, I do >> not need an index action and the urls do look different. For >> example, I >> want /user/:user_id/avatar to show the user avatar, >> /user/:user_id/avatar;edit to change the avatar etc. > > > map.resources :people do |people| > people.resource :avatar > end > > avatar_url(:person_id => person) # => /people/5/avatar > edit_avatar_url(:person_id => person) # => /people/5/avatar;edit > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
DHH wrote:> map.resources :people do |people| > people.resource :avatar > end > > avatar_url(:person_id => person) # => /people/5/avatar > edit_avatar_url(:person_id => person) # => /people/5/avatar;editGreat, thanks! I guess I should not have missed this blogpost: http://weblog.rubyonrails.org/2007/2/6/rails-1-2-2-sqlite3-gems-singular-resources One last thing to mention: The avatar controller has to be singular, too. This means the controller name (AvatarController) and the file name (avatar_controller.rb). I missed the file name first, which took me quite some time to fiddle out... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---