Is it possible to manually pass a value to the model from a controller? thanks --~--~---------~--~----~------------~-------~--~----~ 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 7 Jan 2008, at 17:56, B wrote:> > Is it possible to manually pass a value to the model from a > controller?I''m not sure what you mean. Obviously from your controller you can do some_object.something = :foo or some_object.create(:foo => ''Bob'' , :bar => 23) If you gave an example of what you were trying to do someone might be able to construct a more meaningful answer. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Is it possible to manually pass a value to the model from a controller? thanks --~--~---------~--~----~------------~-------~--~----~ 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 am using restful_authentication with attachment_fu. I want to have the file directory used based on the user_id so that every user has its own directory. I tried modifying the path_prefix (the variable that specifies which folder to use) in the controller, this made the change within the database but it still saves the file in the default directory (public/fileupload) Here is the code @fileupload.path_prefix = ''public/tester'' + (self.current_user.id).to_s The plugin will only use the folder specified in the model and not the controller. I don''t have access to the userid in the upload model (its only present in the controllers). So I was wondering if I can pass in the userId from the controller into the model somehow. On Jan 7, 1:04 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 Jan 2008, at 17:56, B wrote: > > > > > Is it possible to manually pass a value to the model from a > > controller? > > I''m not sure what you mean. Obviously from your controller you can do > some_object.something = :foo > > or > > some_object.create(:foo => ''Bob'' , :bar => 23) > > If you gave an example of what you were trying to do someone might be > able to construct a more meaningful answer. > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 Jan 7, 2008 1:54 PM, B <bilalallawala-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am using restful_authentication with attachment_fu. I want to have > the file directory used based on the user_id so that every user has > its own directory. I tried modifying the path_prefix (the variable > that specifies which folder to use) in the > controller, this made the change within the database but it still > saves the file in the default directory (public/fileupload) > Here is the code > > @fileupload.path_prefix = ''public/tester'' + > (self.current_user.id).to_s > > The plugin will only use the folder specified in the model and not the > controller. I don''t have access to the userid in the upload model (its > only present in the controllers). So I was wondering if I can pass in > the userId from the controller into the model somehow.I think that the right way to do this is to override the method full_filename in your model Here''s the default implementation (in plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb) # Gets the full path to the filename in this format: # # # This assumes a model name like MyModel # # public/#{table_name} is the default filesystem path # RAILS_ROOT/public/my_models/5/blah.jpg # # Overwrite this method in your model to customize the filename. # The optional thumbnail argument will output the thumbnail''s filename. def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))) end So something like User < ActiveRecord::Base has_attachment ... def full_filename(thumbnail = nil) File.join(RAILS_ROOT, "public/tester/#{id}", *partitioned_path(thumbnail_name_for(thumbnail))) end Assuming you don''t need a separate path for the thumbnails. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 Thanks for your response Unfortunately only the controller has access to the user id. So I can''t make the foldername based on the user id in the model. Is there anyway I can pass the value from the controller to the model? On Jan 7, 6:11 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 7, 2008 1:54 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am using restful_authentication with attachment_fu. I want to have > > the file directory used based on the user_id so that every user has > > its own directory. I tried modifying the path_prefix (the variable > > that specifies which folder to use) in the > > controller, this made the change within the database but it still > > saves the file in the default directory (public/fileupload) > > Here is the code > > > @fileupload.path_prefix = ''public/tester'' + > > (self.current_user.id).to_s > > > The plugin will only use the folder specified in the model and not the > > controller. I don''t have access to the userid in the upload model (its > > only present in the controllers). So I was wondering if I can pass in > > the userId from the controller into the model somehow. > > I think that the right way to do this is to override the method > full_filename in your model > > Here''s the default implementation (in > plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb) > # Gets the full path to the filename in this format: > # > # # This assumes a model name like MyModel > # # public/#{table_name} is the default filesystem path > # RAILS_ROOT/public/my_models/5/blah.jpg > # > # Overwrite this method in your model to customize the filename. > # The optional thumbnail argument will output the thumbnail''s filename. > def full_filename(thumbnail = nil) > file_system_path = (thumbnail ? thumbnail_class : > self).attachment_options[:path_prefix].to_s > File.join(RAILS_ROOT, file_system_path, > *partitioned_path(thumbnail_name_for(thumbnail))) > end > > So something like > > User < ActiveRecord::Base > > has_attachment ... > > def full_filename(thumbnail = nil) > File.join(RAILS_ROOT, "public/tester/#{id}", > *partitioned_path(thumbnail_name_for(thumbnail))) > end > > Assuming you don''t need a separate path for the thumbnails. > > -- > Rick DeNatale > > My blog on Rubyhttp://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Of course there is! Define a method in the model: def method(user_id) end and then call it from the controller, passing in user_id. On Jan 8, 2008 12:22 PM, B <bilalallawala-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi > > Thanks for your response > > Unfortunately only the controller has access to the user id. So I > can''t make the foldername based on the user id in the model. Is there > anyway I can pass the value from the controller to the model? > > > > On Jan 7, 6:11 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Jan 7, 2008 1:54 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > I am using restful_authentication with attachment_fu. I want to have > > > the file directory used based on the user_id so that every user has > > > its own directory. I tried modifying the path_prefix (the variable > > > that specifies which folder to use) in the > > > controller, this made the change within the database but it still > > > saves the file in the default directory (public/fileupload) > > > Here is the code > > > > > @fileupload.path_prefix = ''public/tester'' + > > > (self.current_user.id).to_s > > > > > The plugin will only use the folder specified in the model and not the > > > controller. I don''t have access to the userid in the upload model (its > > > only present in the controllers). So I was wondering if I can pass in > > > the userId from the controller into the model somehow. > > > > I think that the right way to do this is to override the method > > full_filename in your model > > > > Here''s the default implementation (in > > > plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb) > > # Gets the full path to the filename in this format: > > # > > # # This assumes a model name like MyModel > > # # public/#{table_name} is the default filesystem path > > # RAILS_ROOT/public/my_models/5/blah.jpg > > # > > # Overwrite this method in your model to customize the filename. > > # The optional thumbnail argument will output the thumbnail''s > filename. > > def full_filename(thumbnail = nil) > > file_system_path = (thumbnail ? thumbnail_class : > > self).attachment_options[:path_prefix].to_s > > File.join(RAILS_ROOT, file_system_path, > > *partitioned_path(thumbnail_name_for(thumbnail))) > > end > > > > So something like > > > > User < ActiveRecord::Base > > > > has_attachment ... > > > > def full_filename(thumbnail = nil) > > File.join(RAILS_ROOT, "public/tester/#{id}", > > *partitioned_path(thumbnail_name_for(thumbnail))) > > end > > > > Assuming you don''t need a separate path for the thumbnails. > > > > -- > > Rick DeNatale > > > > My blog on Rubyhttp://talklikeaduck.denhaven2.com/ > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Not working :( I get undefined method `printval'' for #<FileuploadController:0x57fea90> i created a def printval(userid) in the model. I even tried passing the value in the session in the controller but I can''t even seem to access sessions in the model On Jan 7, 8:56 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Of course there is! Define a method in the model: > > def method(user_id) > > end > > and then call it from the controller, passing in user_id. > > On Jan 8, 2008 12:22 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi > > > Thanks for your response > > > Unfortunately only the controller has access to the user id. So I > > can''t make the foldername based on the user id in the model. Is there > > anyway I can pass the value from the controller to the model? > > > On Jan 7, 6:11 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Jan 7, 2008 1:54 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am using restful_authentication with attachment_fu. I want to have > > > > the file directory used based on the user_id so that every user has > > > > its own directory. I tried modifying the path_prefix (the variable > > > > that specifies which folder to use) in the > > > > controller, this made the change within the database but it still > > > > saves the file in the default directory (public/fileupload) > > > > Here is the code > > > > > @fileupload.path_prefix = ''public/tester'' + > > > > (self.current_user.id).to_s > > > > > The plugin will only use the folder specified in the model and not the > > > > controller. I don''t have access to the userid in the upload model (its > > > > only present in the controllers). So I was wondering if I can pass in > > > > the userId from the controller into the model somehow. > > > > I think that the right way to do this is to override the method > > > full_filename in your model > > > > Here''s the default implementation (in > > > plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb) > > > # Gets the full path to the filename in this format: > > > # > > > # # This assumes a model name like MyModel > > > # # public/#{table_name} is the default filesystem path > > > # RAILS_ROOT/public/my_models/5/blah.jpg > > > # > > > # Overwrite this method in your model to customize the filename. > > > # The optional thumbnail argument will output the thumbnail''s > > filename. > > > def full_filename(thumbnail = nil) > > > file_system_path = (thumbnail ? thumbnail_class : > > > self).attachment_options[:path_prefix].to_s > > > File.join(RAILS_ROOT, file_system_path, > > > *partitioned_path(thumbnail_name_for(thumbnail))) > > > end > > > > So something like > > > > User < ActiveRecord::Base > > > > has_attachment ... > > > > def full_filename(thumbnail = nil) > > > File.join(RAILS_ROOT, "public/tester/#{id}", > > > *partitioned_path(thumbnail_name_for(thumbnail))) > > > end > > > > Assuming you don''t need a separate path for the thumbnails. > > > > -- > > > Rick DeNatale > > > > My blog on Rubyhttp://talklikeaduck.denhaven2.com/ > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You should be calling it on an instance of the model, For example file_upload = FileUpload.find(:first) file_upload.printval(user_id) On Jan 8, 2008 1:06 PM, B <bilalallawala-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Not working :( > I get > undefined method `printval'' for #<FileuploadController:0x57fea90> > > i created a def printval(userid) in the model. I even tried passing > the value in the session in the controller but I can''t even seem to > access sessions in the model > > > > On Jan 7, 8:56 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Of course there is! Define a method in the model: > > > > def method(user_id) > > > > end > > > > and then call it from the controller, passing in user_id. > > > > On Jan 8, 2008 12:22 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Hi > > > > > Thanks for your response > > > > > Unfortunately only the controller has access to the user id. So I > > > can''t make the foldername based on the user id in the model. Is there > > > anyway I can pass the value from the controller to the model? > > > > > On Jan 7, 6:11 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Jan 7, 2008 1:54 PM, B <bilalallaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am using restful_authentication with attachment_fu. I want to > have > > > > > the file directory used based on the user_id so that every user > has > > > > > its own directory. I tried modifying the path_prefix (the variable > > > > > that specifies which folder to use) in the > > > > > controller, this made the change within the database but it still > > > > > saves the file in the default directory (public/fileupload) > > > > > Here is the code > > > > > > > @fileupload.path_prefix = ''public/tester'' + > > > > > (self.current_user.id).to_s > > > > > > > The plugin will only use the folder specified in the model and not > the > > > > > controller. I don''t have access to the userid in the upload model > (its > > > > > only present in the controllers). So I was wondering if I can pass > in > > > > > the userId from the controller into the model somehow. > > > > > > I think that the right way to do this is to override the method > > > > full_filename in your model > > > > > > Here''s the default implementation (in > > > > > > plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb) > > > > # Gets the full path to the filename in this format: > > > > # > > > > # # This assumes a model name like MyModel > > > > # # public/#{table_name} is the default filesystem path > > > > # RAILS_ROOT/public/my_models/5/blah.jpg > > > > # > > > > # Overwrite this method in your model to customize the > filename. > > > > # The optional thumbnail argument will output the > thumbnail''s > > > filename. > > > > def full_filename(thumbnail = nil) > > > > file_system_path = (thumbnail ? thumbnail_class : > > > > self).attachment_options[:path_prefix].to_s > > > > File.join(RAILS_ROOT, file_system_path, > > > > *partitioned_path(thumbnail_name_for(thumbnail))) > > > > end > > > > > > So something like > > > > > > User < ActiveRecord::Base > > > > > > has_attachment ... > > > > > > def full_filename(thumbnail = nil) > > > > File.join(RAILS_ROOT, "public/tester/#{id}", > > > > *partitioned_path(thumbnail_name_for(thumbnail))) > > > > end > > > > > > Assuming you don''t need a separate path for the thumbnails. > > > > > > -- > > > > Rick DeNatale > > > > > > My blog on Rubyhttp://talklikeaduck.denhaven2.com/ > > > > -- > > Ryan Bigghttp://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email. > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---