Hi I''m not sure where in my script I would put my global enviroment variables and when to load them. I would like to create a database table that stores some applications settings. For example the maximum allowed size of an image that the user may upload. Where in the rails app would I load that data and where would I store it so it is accessible in both the model and the controller? thanks for your help Marc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
MarcS wrote:> Hi > > I''m not sure where in my script I would put my global enviroment > variables and when to load them. > I would like to create a database table that stores some applications > settings. > For example the maximum allowed size of an image that the user may > upload. > Where in the rails app would I load that data and where would I store > it so it is accessible in both the model and the controller? > > thanks for your help > > MarcThis can be a choice. In your application.rb def imageSize @imageSize = 1000 #1000kb = 1mb end and in your controller before_filter :imageSize, :only => [:your_controller] -- 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 -~----------~----~----~----~------~----~------~--~---
or... if you only need them in your views, you can put them in your helpers :) def imageSize end and in your view <%= imageSize %> -- 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 -~----------~----~----~----~------~----~------~--~---
This is not a global environment variable. This is business logic that belongs in the model that handles your image uploads. attachment_fu already provides a way to specify max upload size, for instance. Otherwise: class Image < ActiveRecord::Base MAX_IMAGE_SIZE = 10.megabytes def self.max_image_size; MAX_IMAGE_SIZE; end end It certainly doesn''t belong in the controller or the view. Global environment variables are a bad code smell in ruby/rails, mainly a holdover from people with a PHP background, I think. Rein On Sep 3, 12:22 pm, MarcS <marcschue...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > I''m not sure where in my script I would put my global enviroment > variables and when to load them. > I would like to create a database table that stores some applications > settings. > For example the maximum allowed size of an image that the user may > upload. > Where in the rails app would I load that data and where would I store > it so it is accessible in both the model and the controller? > > thanks for your help > > Marc--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rein Henrichs wrote:> This is not a global environment variable. This is business logic that > belongs in the model that handles your image uploads. attachment_fu > already provides a way to specify max upload size, for instance. > > Otherwise: > > class Image < ActiveRecord::Base > > MAX_IMAGE_SIZE = 10.megabytes > def self.max_image_size; MAX_IMAGE_SIZE; end > > end > > It certainly doesn''t belong in the controller or the view. Global > environment variables are a bad code smell in ruby/rails, mainly a > holdover from people with a PHP background, I think. > > ReinYou are right :) and I come from PHP background :D but if he needs global variable to access it, he can place it in the helper if it doesn''t have anything to do with his tabels? -- 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 -~----------~----~----~----~------~----~------~--~---
Jamal: If it is somehow related only to the presentation of information then it may make sense to put it in a helper. It''s always best to encapsulate such things properly to separate concerns and avoid polluting the namespace. Ruby/Rails makes this easy. On Sep 3, 1:05 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Rein Henrichs wrote: > > This is not a global environment variable. This is business logic that > > belongs in the model that handles your image uploads. attachment_fu > > already provides a way to specify max upload size, for instance. > > > Otherwise: > > > class Image < ActiveRecord::Base > > > MAX_IMAGE_SIZE = 10.megabytes > > def self.max_image_size; MAX_IMAGE_SIZE; end > > > end > > > It certainly doesn''t belong in the controller or the view. Global > > environment variables are a bad code smell in ruby/rails, mainly a > > holdover from people with a PHP background, I think. > > > Rein > > You are right :) > > and I come from PHP background :D > > but if he needs global variable to access it, he can place it in the > helper if it doesn''t have anything to do with his tabels? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
thanks for your answers.
You are right .. I come from a php background and back in the days I
always had my config.php file that had all the settings in it.
But what I''d like to do right now is load my settings from a table in
the database and then work with them.
Would I need to create a seperate settings model for that?
I wanna use the size property for example in the following model where
I define the max size of an image that the user can upload
class ArticleImage < ActiveRecord::Base
	belongs_to :article
  has_attachment  :storage => :file_system,
		:content_type => :image,
		:size => 0.bytes..2.megabytes,
		:thumbnails => { :thumb => ''120x120>'' },
		:processor => :MiniMagick
If I create a seperate model for the settings. How would I access that
in here?
Sorry for the newbie questions :)
On Sep 3, 8:17 pm, Rein Henrichs
<rein.henri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Jamal: If it is somehow related only to the presentation of
> information then it may make sense to put it in a helper. It''s
always
> best to encapsulate such things properly to separate concerns and
> avoid polluting the namespace. Ruby/Rails makes this easy.
>
> On Sep 3, 1:05 pm, Jamal Soueidan
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> wrote:
>
> > Rein Henrichs wrote:
> > > This is not a global environment variable. This is business logic
that
> > > belongs in the model that handles your image uploads.
attachment_fu
> > > already provides a way to specify max upload size, for instance.
>
> > > Otherwise:
>
> > > class Image < ActiveRecord::Base
>
> > >   MAX_IMAGE_SIZE = 10.megabytes
> > >   def self.max_image_size; MAX_IMAGE_SIZE; end
>
> > > end
>
> > > It certainly doesn''t belong in the controller or the
view. Global
> > > environment variables are a bad code smell in ruby/rails, mainly
a
> > > holdover from people with a PHP background, I think.
>
> > > Rein
>
> > You are right :)
>
> > and I come from PHP background :D
>
> > but if he needs global variable to access it, he can place it in the
> > helper if it doesn''t have anything to do with his tabels?
>
> > --
> > Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---
You can have a settings table (because you want the client or  
operations people to be able to change it at run-time).
class Setting < ActiveRecord::Base
end
The attributes would be in the migration for name, value, etc.
In the other model/controller/view simply do something like  
Setting.find_by_name("max_image_size").value to get at the setting  
value.
Michael
On Sep 3, 2007, at 1:24 PM, MarcS wrote:
>
> thanks for your answers.
> You are right .. I come from a php background and back in the days I
> always had my config.php file that had all the settings in it.
>
> But what I''d like to do right now is load my settings from a table
in
> the database and then work with them.
> Would I need to create a seperate settings model for that?
>
> I wanna use the size property for example in the following model where
> I define the max size of an image that the user can upload
>
> class ArticleImage < ActiveRecord::Base
> 	belongs_to :article
>
>   has_attachment  :storage => :file_system,
> 		:content_type => :image,
> 		:size => 0.bytes..2.megabytes,
> 		:thumbnails => { :thumb => ''120x120>'' },
> 		:processor => :MiniMagick
>
> If I create a seperate model for the settings. How would I access that
> in here?
> Sorry for the newbie questions :)
>
> On Sep 3, 8:17 pm, Rein Henrichs
<rein.henri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Jamal: If it is somehow related only to the presentation of
>> information then it may make sense to put it in a helper. It''s
always
>> best to encapsulate such things properly to separate concerns and
>> avoid polluting the namespace. Ruby/Rails makes this easy.
>>
>> On Sep 3, 1:05 pm, Jamal Soueidan
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
>> wrote:
>>
>>> Rein Henrichs wrote:
>>>> This is not a global environment variable. This is business  
>>>> logic that
>>>> belongs in the model that handles your image uploads.
attachment_fu
>>>> already provides a way to specify max upload size, for
instance.
>>
>>>> Otherwise:
>>
>>>> class Image < ActiveRecord::Base
>>
>>>>   MAX_IMAGE_SIZE = 10.megabytes
>>>>   def self.max_image_size; MAX_IMAGE_SIZE; end
>>
>>>> end
>>
>>>> It certainly doesn''t belong in the controller or the
view. Global
>>>> environment variables are a bad code smell in ruby/rails,
mainly a
>>>> holdover from people with a PHP background, I think.
>>
>>>> Rein
>>
>>> You are right :)
>>
>>> and I come from PHP background :D
>>
>>> but if he needs global variable to access it, he can place it in
the
>>> helper if it doesn''t have anything to do with his tabels?
>>
>>> --
>>> Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---
Michael Latta wrote:> You can have a settings table (because you want the client or > operations people to be able to change it at run-time). > > class Setting < ActiveRecord::Base > end > > The attributes would be in the migration for name, value, etc. > > In the other model/controller/view simply do something like > Setting.find_by_name("max_image_size").value to get at the setting > value. > > Michaelyou may also want to use a .yml file and load this using your config file, you cant change the settings at runtime but it will be a lot better from the performance side of things -- 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 -~----------~----~----~----~------~----~------~--~---
thanks for your answers On Sep 4, 8:50 am, Scott A s <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Michael Latta wrote: > > You can have a settings table (because you want the client or > > operations people to be able to change it at run-time). > > > class Setting < ActiveRecord::Base > > end > > > The attributes would be in the migration for name, value, etc. > > > In the other model/controller/view simply do something like > > Setting.find_by_name("max_image_size").value to get at the setting > > value. > > > Michael > > you may also want to use a .yml file and load this using your config > file, you cant change the settings at runtime but it will be a lot > better from the performance side of things > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
On 9/4/07, Scott A s <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:><snip>> > you may also want to use a .yml file and load this using your config > file, you cant change the settings at runtime but it will be a lot > better from the performance side of thingsYou can change settings at runtime by using YAML.dump to save your new settings to the config file. The bug tracking system Retrospectiva <http://www.retrospectiva.org> uses a YAML based general settings and configuration file which is managed by a configuration manager class. Read the following code for more information: <http://retrospectiva.org/browse/trunk/lib/retrospectiva/configuration_manager/lib/configuration_manager.rb> Adam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---