Max Williams
2007-Sep-08 08:37 UTC
method "movie_file=" can someone explain this to me please?
I''m using this method, adapted from a similar one for pictures, and it works fine but i don''t really understand how: def movie_file=(input_data) self.filename = input_data.original_filename self.content_type = input_data.content_type.chomp self.file_data = input_data.read end i''m using the new fields this creates, such as filename, content_type etc, in my other methods, and it all works, but what''s the meaning of a method ending in an equals sign like this? I''ve had errors with other classes where it says things like "missing method ''story=''" in my story controller (or maybe it was the model). I''m guessing that this is a standard rails way of doing something but it''s got me puzzled...at a guess, i''d say that it''s like an add-on to a constructor, that gets called after the constructor is called, to add some new fields to the object? Is that right? thanks max -- 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 -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2007-Sep-08 09:33 UTC
Re: method "movie_file=" can someone explain this to me please?
On 08 Sep 2007, at 10:37, Max Williams wrote:> def movie_file=(input_data) > self.filename = input_data.original_filename > self.content_type = input_data.content_type.chomp > self.file_data = input_data.read > end > > i''m using the new fields this creates, such as filename, content_type > etc, in my other methods, and it all works, but what''s the meaning > of a > method ending in an equals sign like this? I''ve had errors with other > classes where it says things like "missing method ''story=''" in my > story > controller (or maybe it was the model).It''s an assign method. def movie_file #code end The above is used to GET the movie file def movie_file=(x) #code end The above is used to SET the movie file I''ll simplify a little, but suppose you don''t have a field movie_file in your model (i.e. database table), you can use this method to pretend it''s there. You then handle it with the variable "x" so that it does something useful. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gene tani
2007-Sep-08 14:04 UTC
Re: method "movie_file=" can someone explain this to me please?
On Sep 8, 1:37 am, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m using this method, adapted from a similar one for pictures, and it > works fine but i don''t really understand how: > > def movie_file=(input_data) > self.filename = input_data.original_filename > self.content_type = input_data.content_type.chomp > self.file_data = input_data.read > end > > i''m using the new fields this creates, such as filename, content_type > etc, in my other methods, and it all works, but what''s the meaning of a > method ending in an equals sign like this? I''ve had errors with other > classes where it says things like "missing method ''story=''" in my story > controller (or maybe it was the model). > > I''m guessing that this is a standard rails way of doing something but > it''s got me puzzled...at a guess, i''d say that it''s like an add-on to a > constructor, that gets called after the constructor is called, to add > some new fields to the object? Is that right? > > thanks > max > -- > Posted viahttp://www.ruby-forum.com/.att_accessor is a way of defining "virtual" AR attributes or virtual columns in a table, the canonical example being "password" and "password_confirm" which are taken from a user''s registration form but never saved to database (the hashed password and salt are saved). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Max Williams
2007-Sep-09 13:58 UTC
Re: method "movie_file=" can someone explain this to me plea
Peter De Berdt wrote:> On 08 Sep 2007, at 10:37, Max Williams wrote:> > def movie_file=(x) > #code > end > > The above is used to SET the movie file >ahhh...of course :) I always used attr_accessor in ruby (i''ve only done a few bits of non-rails ruby coding) and forgot about the individual set and get methods. That all makes sense now, thanks both! -- 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 -~----------~----~----~----~------~----~------~--~---