From adam at thewilliams.ws Mon Mar 2 06:44:05 2009 From: adam at thewilliams.ws (Adam Williams) Date: Mon, 2 Mar 2009 06:44:05 -0500 Subject: [raleigh.rb] rails routing quiz -- contributions welcome In-Reply-To: <0CA49B7B-7074-4B3F-94CE-71C89B5AFDEB@gmail.com> References: <0CA49B7B-7074-4B3F-94CE-71C89B5AFDEB@gmail.com> Message-ID: <0E53B308-5143-4F4B-9A29-66C5EB2C961E@thewilliams.ws> Matthew, Is it possible to get {:account => {:invitation_code => 'CODE'}} out of a route without query parameters? I looked all through routing_test.rb (the actionpack 2.3.0 one, that is) and could not find a test which indicated that routing.rb could handle this. AFAIK, segments are key => value. If you change line 19 to this: assert_routing '/accounts/new/CODE', hash_for_named_route(:new_account).merge(:invitation_code => 'CODE') Then you can get both tests passing with: map.resources :accounts map.new_account '/accounts/new/:invitation_code', :controller => 'accounts', :action => 'new', :conditions => {:method => :get}, :defaults => {:invitation_code => nil} adam On Feb 27, 2009, at 3:40 AM, Matthew Todd wrote: > Hi, all -- > > Consider this a Friday "Ruby Quiz", except it's quite Rails-specific. > > In essence, I'm looking to get this test to pass: > http://gist.github.com/71344 > > I'm on a quest to make my sign up urls look prettier, and I want > config/routes.rb to be the *only* place that has to change -- not my > named route calls, not my AccountsController. This should be purely > a routing concern. > > I've written the test with minimal dependencies, so you should be > able to > $ git clone git://gist.github.com/71344.git gist-71344 > $ ruby gist-71344/routing_test.rb > > regardless of your rspec/shoulda/etc. preference. > > Thanks! Have fun! -- Matthew > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members From martin.streicher at gmail.com Mon Mar 2 18:13:00 2009 From: martin.streicher at gmail.com (Martin Streicher) Date: Mon, 2 Mar 2009 18:13:00 -0500 Subject: [raleigh.rb] Content delivery networks and Rails Message-ID: I am authoring an article for Amazon Cloudfront. Are there recommended techniques for working with content delivery networks in Rails? I have seen and used ActionController::Base.asset_host and am aware of the date parameter that Rails can attach to each static image to reflect its last modified time. Are there other build techniques and coding techniques to work well with CDNs? For instance, does anyone refer to fixed IDs in code which are replaced during a build with the latest and greatest version of an asset? If so, is this a rake task? I'll do some Googling, but thought I would ask my local peers, too. The article will be based on Rails, so will assist the community at large when published next month. Martin -- Martin Streicher Fresh Pixels, Bytes, and Commas, Baked Daily web: http://www.linkedin.com/in/mstreicher email: martin.streicher at gmail.com gtalk: martin.streicher at gmail.com aim: horatiogadget skype: martin.s.streicher phone: 919.741.4182 From matthew.todd at gmail.com Tue Mar 3 00:37:08 2009 From: matthew.todd at gmail.com (Matthew Todd) Date: Tue, 3 Mar 2009 08:37:08 +0300 Subject: [raleigh.rb] rails routing quiz -- contributions welcome In-Reply-To: <0E53B308-5143-4F4B-9A29-66C5EB2C961E@thewilliams.ws> References: <0CA49B7B-7074-4B3F-94CE-71C89B5AFDEB@gmail.com> <0E53B308-5143-4F4B-9A29-66C5EB2C961E@thewilliams.ws> Message-ID: <83406610-7ABE-42AE-84C5-2C01FCF485E9@gmail.com> On Mar 2, 2009, at 2:44 PM, Adam Williams wrote: > Matthew, Thanks, Adam -- > Is it possible to get {:account => {:invitation_code => 'CODE'}} > out of a route without query parameters? I looked all through > routing_test.rb (the actionpack 2.3.0 one, that is) and could not > find a test which indicated that routing.rb could handle this. > AFAIK, segments are key => value. Well, that was my hope, but I've just looked through routing_test.rb as well and can't seem to find anything either. One way forward might be Sven Fuchs' routing-filter plugin[1] (which we're already using to put the current locale at the head of the path) -- it allows for around_recognize and around_generate hooks to mirror-image modify the incoming parameters and the outgoing path, respectively. Though that starts to feel hinky. We'll probably proceed as you suggest below. > If you change line 19 to this: > > assert_routing '/accounts/new/CODE', hash_for_named_route > (:new_account).merge(:invitation_code => 'CODE') > > Then you can get both tests passing with: > > map.resources :accounts > map.new_account '/accounts/new/:invitation_code', > :controller => 'accounts', :action => 'new', > :conditions => {:method => :get}, > :defaults => {:invitation_code => nil} All the best, -- Matthew [1] http://github.com/svenfuchs/routing-filter From mshiltonj at gmail.com Tue Mar 3 16:31:41 2009 From: mshiltonj at gmail.com (Steven Hilton) Date: Tue, 3 Mar 2009 16:31:41 -0500 Subject: [raleigh.rb] Idiomatic clearing of _one_ association in a has_many relationship? Message-ID: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> This may be a faq, but my google is failing me. Is there an idiomatic way of breaking the association between one specific model in a has_many relationship? Like: [...] @bar = @foo.bars[3] @bar.foo_id = nil @bar.save # @bar is now orphaned [...] '@foo.bars.clear()' is not what I'm looking for. -- Steven Hilton From seancribbs at gmail.com Tue Mar 3 16:54:39 2009 From: seancribbs at gmail.com (Sean Cribbs) Date: Tue, 03 Mar 2009 16:54:39 -0500 Subject: [raleigh.rb] Idiomatic clearing of _one_ association in a has_many relationship? In-Reply-To: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> References: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> Message-ID: <49ADA71F.1020206@gmail.com> I believe this is idiomatic: @foo.bars.delete(@bar) It doesn't delete @bar from the DB, but sets its FK to null. Sean Steven Hilton wrote: > This may be a faq, but my google is failing me. > > Is there an idiomatic way of breaking the association between one > specific model in a has_many relationship? > > Like: > [...] > @bar = @foo.bars[3] > @bar.foo_id = nil > @bar.save # @bar is now orphaned > [...] > > '@foo.bars.clear()' is not what I'm looking for. > > > > From seancribbs at gmail.com Tue Mar 3 16:55:27 2009 From: seancribbs at gmail.com (Sean Cribbs) Date: Tue, 03 Mar 2009 16:55:27 -0500 Subject: [raleigh.rb] Idiomatic clearing of _one_ association in a has_many relationship? In-Reply-To: <49ADA71F.1020206@gmail.com> References: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> <49ADA71F.1020206@gmail.com> Message-ID: <49ADA74F.7070201@gmail.com> Woops - if you have :dependent => :destroy or :dependent => :delete_all, it will be removed from the DB. Sean Sean Cribbs wrote: > I believe this is idiomatic: > > @foo.bars.delete(@bar) > > It doesn't delete @bar from the DB, but sets its FK to null. > > Sean > > Steven Hilton wrote: >> This may be a faq, but my google is failing me. >> >> Is there an idiomatic way of breaking the association between one >> specific model in a has_many relationship? >> >> Like: >> [...] >> @bar = @foo.bars[3] >> @bar.foo_id = nil >> @bar.save # @bar is now orphaned >> [...] >> >> '@foo.bars.clear()' is not what I'm looking for. >> >> >> >> > > From mshiltonj at gmail.com Tue Mar 3 17:07:25 2009 From: mshiltonj at gmail.com (Steven Hilton) Date: Tue, 3 Mar 2009 17:07:25 -0500 Subject: [raleigh.rb] Idiomatic clearing of _one_ association in a has_many relationship? In-Reply-To: <49ADA74F.7070201@gmail.com> References: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> <49ADA71F.1020206@gmail.com> <49ADA74F.7070201@gmail.com> Message-ID: <8308260d0903031407v742d0703meb2b10868a436d13@mail.gmail.com> Ah! There it is, right in the docs. Thanks for the heads up. I guess I was blind to 'delete' while searching because I didn't want to, you know, delete anything. On Tue, Mar 3, 2009 at 4:55 PM, Sean Cribbs wrote: > Woops - if you have :dependent => :destroy or :dependent => :delete_all, it > will be removed from the DB. > > Sean > > Sean Cribbs wrote: >> >> I believe this is idiomatic: >> >> @foo.bars.delete(@bar) >> >> It doesn't delete @bar from the DB, but sets its FK to null. >> >> Sean >> >> Steven Hilton wrote: >>> >>> This may be a faq, but my google is failing me. >>> >>> Is there an idiomatic way of breaking the association between one >>> specific model in a has_many relationship? >>> >>> Like: >>> [...] >>> @bar = @foo.bars[3] >>> @bar.foo_id = nil >>> @bar.save ?# @bar is now orphaned >>> [...] >>> >>> '@foo.bars.clear()' is not what I'm looking for. >>> >>> >>> >>> >> >> > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -- Steven Hilton From rick.denatale at gmail.com Tue Mar 3 18:02:14 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 3 Mar 2009 18:02:14 -0500 Subject: [raleigh.rb] Idiomatic clearing of _one_ association in a has_many relationship? In-Reply-To: <49ADA74F.7070201@gmail.com> References: <8308260d0903031331h69f876e0v93919961d434dea2@mail.gmail.com> <49ADA71F.1020206@gmail.com> <49ADA74F.7070201@gmail.com> Message-ID: On Tue, Mar 3, 2009 at 4:55 PM, Sean Cribbs wrote: > Woops - if you have :dependent => :destroy or :dependent => :delete_all, it > will be removed from the DB. > > Sean > Keerect, And the difference of course is that :destroy runs the destroy method first, while :delete_all (or :delete on a belongs_to or has_one association) just removes the row(s) from the database. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -------------- next part -------------- An HTML attachment was scrubbed... URL: From pelargir at gmail.com Tue Mar 10 10:00:31 2009 From: pelargir at gmail.com (Matthew Bass) Date: Tue, 10 Mar 2009 10:00:31 -0400 Subject: [raleigh.rb] Enumerable#group_by is gobbling up memory Message-ID: Has anyone else experienced problems with Rails' Enumerable#group_by method hogging memory when dealing with large arrays of ActiveRecord objects? I have a view in my app that uses group_by on a collection of AR objects (5600+). When I hit this view, Rails spins for a good minute or so and the memory usage of the Ruby process climbs from 55 MB to peak out around 650 MB. I don't see anything obvious in the implementation of group_by that would explain this phenomenon: def group_by inject({}) do |groups, element| (groups[yield(element)] ||= []) << element groups end I tried re-implementing group_by and clearing the array when finished, to no avail: def group_by(array, key) groups = {} array.each { |e| (groups[e.send(key)] ||= []) << e } array.clear groups end Setting the array to nil and calling GC.start didn't help either. Anyone have suggestions as to how I could refactor group_by to avoid this memory problem? It looks to me like the hashing process itself is what's gobbling up the memory, but I could be wrong. Every time I hit the page, the memory usage increases. (Letting the database handle the grouping is *not* an option at this point.) Matthew -------------- next part -------------- An HTML attachment was scrubbed... URL: From seancribbs at gmail.com Tue Mar 10 10:53:44 2009 From: seancribbs at gmail.com (Sean Cribbs) Date: Tue, 10 Mar 2009 10:53:44 -0400 Subject: [raleigh.rb] Enumerable#group_by is gobbling up memory In-Reply-To: References: Message-ID: <49B67EF8.6090000@gmail.com> This may be a little crazy, but could you use select_values to get the id+attribute that you group by, and then do a map on each group later to load the AR objects? Sean Matthew Bass wrote: > Has anyone else experienced problems with Rails' Enumerable#group_by > method hogging memory when dealing with large arrays of ActiveRecord > objects? > > I have a view in my app that uses group_by on a collection of AR > objects (5600+). When I hit this view, Rails spins for a good minute > or so and the memory usage of the Ruby process climbs from 55 MB to > peak out around 650 MB. I don't see anything obvious in the > implementation of group_by that would explain this phenomenon: > > def group_by > inject({}) do |groups, element| > (groups[yield(element)] ||= []) << element > groups > end > > I tried re-implementing group_by and clearing the array when finished, > to no avail: > > def group_by(array, key) > groups = {} > array.each { |e| (groups[e.send(key)] ||= []) << e } > array.clear > groups > end > > Setting the array to nil and calling GC.start didn't help either. > > Anyone have suggestions as to how I could refactor group_by to avoid > this memory problem? It looks to me like the hashing process itself is > what's gobbling up the memory, but I could be wrong. Every time I hit > the page, the memory usage increases. (Letting the database handle the > grouping is *not* an option at this point.) > > Matthew > ------------------------------------------------------------------------ > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnwlong2000 at gmail.com Tue Mar 10 11:01:27 2009 From: johnwlong2000 at gmail.com (John W. Long) Date: Tue, 10 Mar 2009 11:01:27 -0400 Subject: [raleigh.rb] Enumerable#group_by is gobbling up memory In-Reply-To: References: Message-ID: Have you considered Rails 2.3's find_in_batches? It lets you do stuff like this: Customer.find_in_batches(:conditions => {:active => true}) do | customer_group| customer_group.each { |customer| customer.update_account_balance! } end More here: http://guides.rubyonrails.org/2_3_release_notes.html#batch-processing -- John Long http://wiseheartdesign.com On Mar 10, 2009, at 10:00 AM, Matthew Bass wrote: > Has anyone else experienced problems with Rails' Enumerable#group_by > method hogging memory when dealing with large arrays of ActiveRecord > objects? > > I have a view in my app that uses group_by on a collection of AR > objects (5600+). When I hit this view, Rails spins for a good minute > or so and the memory usage of the Ruby process climbs from 55 MB to > peak out around 650 MB. I don't see anything obvious in the > implementation of group_by that would explain this phenomenon: > > def group_by > inject({}) do |groups, element| > (groups[yield(element)] ||= []) << element > groups > end > > I tried re-implementing group_by and clearing the array when > finished, to no avail: > > def group_by(array, key) > groups = {} > array.each { |e| (groups[e.send(key)] ||= []) << e } > array.clear > groups > end > > Setting the array to nil and calling GC.start didn't help either. > > Anyone have suggestions as to how I could refactor group_by to avoid > this memory problem? It looks to me like the hashing process itself > is what's gobbling up the memory, but I could be wrong. Every time I > hit the page, the memory usage increases. (Letting the database > handle the grouping is *not* an option at this point.) > > Matthew > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members From info at lojic.com Tue Mar 10 11:06:59 2009 From: info at lojic.com (Brian Adkins) Date: Tue, 10 Mar 2009 11:06:59 -0400 Subject: [raleigh.rb] Enumerable#group_by is gobbling up memory In-Reply-To: References: Message-ID: <49B68213.6090007@lojic.com> Matthew Bass wrote, On 3/10/09 10:00 AM: > Has anyone else experienced problems with Rails' Enumerable#group_by method > hogging memory when dealing with large arrays of ActiveRecord objects? > I have a view in my app that uses group_by on a collection of AR objects > (5600+). When I hit this view, Rails spins for a good minute or so and the > memory usage of the Ruby process climbs from 55 MB to peak out around 650 > MB. I don't see anything obvious in the implementation of group_by that > would explain this phenomenon: Matthew, I haven't experienced this, but I have some questions: 1) Have you verified that the number of AR objects is truly ~5600 ? i.e. you didn't accidentally retrieve a cartesian product :) 2) What is your estimate of the average size of the AR objects ? 3) As a comparison, how much memory is used if you simply iterate through the collection and reference each object so as to bring it into memory and append it to an Array? (650 MB - 55 MB) / 5600 > 108K/object which seems quite high > def group_by > inject({}) do |groups, element| > (groups[yield(element)] ||= []) << element > groups > end > > I tried re-implementing group_by and clearing the array when finished, to no > avail: > > def group_by(array, key) > groups = {} > array.each { |e| (groups[e.send(key)] ||= []) << e } > array.clear > groups > end > > Setting the array to nil and calling GC.start didn't help either. > > Anyone have suggestions as to how I could refactor group_by to avoid this > memory problem? It looks to me like the hashing process itself is what's > gobbling up the memory, but I could be wrong. Every time I hit the page, the > memory usage increases. (Letting the database handle the grouping is *not* > an option at this point.) > > Matthew > > > > ------------------------------------------------------------------------ > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members -- Brian Adkins Lojic Technologies, LLC http://lojic.com/ 919-946-7547 (mobile) From michael at webadvocate.com Tue Mar 10 11:18:20 2009 From: michael at webadvocate.com (Michael Klett) Date: Tue, 10 Mar 2009 11:18:20 -0400 Subject: [raleigh.rb] Enumerable#group_by is gobbling up memory In-Reply-To: References: Message-ID: Could something you're doing in the group_by call be triggering Rails to load (and cache) the associations (has_many etc) to your first order AR objects? Michael On Tue, Mar 10, 2009 at 10:00 AM, Matthew Bass wrote: > Has anyone else experienced problems with Rails' Enumerable#group_by method > hogging memory when dealing with large arrays of ActiveRecord objects? > I have a view in my app that uses group_by on a collection of AR objects > (5600+). When I hit this view, Rails spins for a good minute or so and the > memory usage of the Ruby process climbs from 55 MB to peak out around 650 > MB. I don't see anything obvious in the implementation of group_by that > would explain this phenomenon: > > def group_by > inject({}) do |groups, element| > (groups[yield(element)] ||= []) << element > groups > end > > I tried re-implementing group_by and clearing the array when finished, to > no avail: > > def group_by(array, key) > groups = {} > array.each { |e| (groups[e.send(key)] ||= []) << e } > array.clear > groups > end > > Setting the array to nil and calling GC.start didn't help either. > > Anyone have suggestions as to how I could refactor group_by to avoid this > memory problem? It looks to me like the hashing process itself is what's > gobbling up the memory, but I could be wrong. Every time I hit the page, the > memory usage increases. (Letting the database handle the grouping is *not* > an option at this point.) > > Matthew > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at ravinggenius.com Fri Mar 13 13:27:27 2009 From: thomas at ravinggenius.com (Thomas Ingram) Date: Fri, 13 Mar 2009 13:27:27 -0400 Subject: [raleigh.rb] Noob deployment questions Message-ID: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> I am getting close to needing to deploy a Rails application for the first time (exciting!). I am using DreamHost, Passenger, git and Capistrano. I setup and deployed to a staging server last night. This was the first time doing anything with Capistrano or Passenger, but it wasn't hard to figure out. The site took a while to load, and when it finally did, I got an error because database.yml was missing. That makes since, because it is in .gitignore. Now for a few questions... If I have git set to ignore database.yml, how do I get it to the production server? I don't think copying the file manually is a good idea. Should copy it to the shared folder that Capistrano sets up, then I add a step in deploy.rb to update a symlink? What would be the best way to handle this? I have some sensitive information in deploy.rb. No passwords, but nobody needs to know the username or server name in there. Should I add this file to .gitignore? It seems that this information would be different for everybody, so I think that might be the best way to go. One more question: Passenger documentation says to touch tmp/restart.txt when you need to restart. Does Capistrano detect Passenger and do this automatically? Or do I need to add this to deploy.rb also? Thank you all for your help. -- Thomas ><> Raving Genius? - foaming at the brain? m: 919 449.6305 e: thomas at ravinggenius.com w: http://log.ravinggenius.com/ wii: 6751 1365 9898 2150 From mike at hales.ws Fri Mar 13 13:40:17 2009 From: mike at hales.ws (Michael Hale) Date: Fri, 13 Mar 2009 13:40:17 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> Message-ID: <60190a730903131040j6a52c9fsdb7cdae4791513da@mail.gmail.com> On Fri, Mar 13, 2009 at 1:27 PM, Thomas Ingram wrote: > I am getting close to needing to deploy a Rails application for the > first time (exciting!). I am using DreamHost, Passenger, git and > Capistrano. I setup and deployed to a staging server last night. This > was the first time doing anything with Capistrano or Passenger, but it > wasn't hard to figure out. The site took a while to load, and when it > finally did, I got an error because database.yml was missing. That > makes since, because it is in .gitignore. Now for a few questions... > > If I have git set to ignore database.yml, how do I get it to the > production server? I don't think copying the file manually is a good > idea. Should copy it to the shared folder that Capistrano sets up, > then I add a step in deploy.rb to update a symlink? What would be the > best way to handle this? I prefer the symlink method you can ad something like this to your deploy.rb: task :symlink_database_yml do run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end after "deploy:symlink", "symlink_database_yml" > > I have some sensitive information in deploy.rb. No passwords, but > nobody needs to know the username or server name in there. Should I > add this file to .gitignore? It seems that this information would be > different for everybody, so I think that might be the best way to go. You can extract the sensitive information into variables and put them in your ~/.caprc > > One more question: Passenger documentation says to touch > tmp/restart.txt when you need to restart. Does Capistrano detect > Passenger and do this automatically? Or do I need to add this to > deploy.rb also? You'll need to add it to deploy.rb manually. For bonus points put in a seperate file under lib/recipes so that you can easily reuse the task across projects. > > Thank you all for your help. > > -- > Thomas ><> > Raving Genius? - foaming at the brain? > m: 919 449.6305 > e: thomas at ravinggenius.com > w: http://log.ravinggenius.com/ > wii: 6751 1365 9898 2150 > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members -- Michael Hale mikehale at gmail.com m: 919.961.7171 jabber: mikehale at gmail.com skype: mhale2243 From mdolian at engineyard.com Fri Mar 13 13:32:47 2009 From: mdolian at engineyard.com (Matthew Dolian) Date: Fri, 13 Mar 2009 11:32:47 -0600 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> Message-ID: <6D493455-1EC1-4208-83A0-A7F0E1C0CF1B@engineyard.com> I would store any yml files that you don't want in your repo on the server somewhere that won't be overwritten on new deploys. Then you just need a quick task in your deploy.rb to symlink any yml files into your application config/ directory. -Matt On Mar 13, 2009, at 11:27 AM, Thomas Ingram wrote: > I am getting close to needing to deploy a Rails application for the > first time (exciting!). I am using DreamHost, Passenger, git and > Capistrano. I setup and deployed to a staging server last night. This > was the first time doing anything with Capistrano or Passenger, but it > wasn't hard to figure out. The site took a while to load, and when it > finally did, I got an error because database.yml was missing. That > makes since, because it is in .gitignore. Now for a few questions... > > If I have git set to ignore database.yml, how do I get it to the > production server? I don't think copying the file manually is a good > idea. Should copy it to the shared folder that Capistrano sets up, > then I add a step in deploy.rb to update a symlink? What would be the > best way to handle this? > > I have some sensitive information in deploy.rb. No passwords, but > nobody needs to know the username or server name in there. Should I > add this file to .gitignore? It seems that this information would be > different for everybody, so I think that might be the best way to go. > > One more question: Passenger documentation says to touch > tmp/restart.txt when you need to restart. Does Capistrano detect > Passenger and do this automatically? Or do I need to add this to > deploy.rb also? > > Thank you all for your help. > > -- > Thomas ><> > Raving Genius? - foaming at the brain? > m: 919 449.6305 > e: thomas at ravinggenius.com > w: http://log.ravinggenius.com/ > wii: 6751 1365 9898 2150 > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members From info at lojic.com Fri Mar 13 13:51:16 2009 From: info at lojic.com (Brian Adkins) Date: Fri, 13 Mar 2009 13:51:16 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> Message-ID: <49BA9D14.2000109@lojic.com> Thomas Ingram wrote, On 3/13/09 1:27 PM: > [...] > The site took a while to load, and when it > finally did, I got an error because database.yml was missing. That > makes since, because it is in .gitignore. Now for a few questions... Just out of curiosity, why do you have database.yml in .gitignore? Do multiple people require their own, unique, non-prod settings? -- Brian Adkins Lojic Technologies, LLC http://lojic.com/ 919-946-7547 (mobile) From otto.hammersmith at gmail.com Fri Mar 13 13:52:32 2009 From: otto.hammersmith at gmail.com (Otto Hammersmith) Date: Fri, 13 Mar 2009 13:52:32 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <6D493455-1EC1-4208-83A0-A7F0E1C0CF1B@engineyard.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <6D493455-1EC1-4208-83A0-A7F0E1C0CF1B@engineyard.com> Message-ID: Deprec has a lot of that sort of stuff built-in. Don't think it would work well with Dreamhost, a number of the recipes assume root access. One thing to point out about passenger on dreamhost, there's no way to cleanly have multiple environments, say a staging and a production. You can do it, but you end up re-setting RAILS_ENV late enough in the startup process that it ends up writing to production.log, anyway. On Fri, Mar 13, 2009 at 1:32 PM, Matthew Dolian wrote: > I would store any yml files that you don't want in your repo on the server > somewhere that won't be overwritten on new deploys. Then you just need a > quick task in your deploy.rb to symlink any yml files into your application > config/ directory. > > -Matt > > > On Mar 13, 2009, at 11:27 AM, Thomas Ingram wrote: > > I am getting close to needing to deploy a Rails application for the >> first time (exciting!). I am using DreamHost, Passenger, git and >> Capistrano. I setup and deployed to a staging server last night. This >> was the first time doing anything with Capistrano or Passenger, but it >> wasn't hard to figure out. The site took a while to load, and when it >> finally did, I got an error because database.yml was missing. That >> makes since, because it is in .gitignore. Now for a few questions... >> >> If I have git set to ignore database.yml, how do I get it to the >> production server? I don't think copying the file manually is a good >> idea. Should copy it to the shared folder that Capistrano sets up, >> then I add a step in deploy.rb to update a symlink? What would be the >> best way to handle this? >> >> I have some sensitive information in deploy.rb. No passwords, but >> nobody needs to know the username or server name in there. Should I >> add this file to .gitignore? It seems that this information would be >> different for everybody, so I think that might be the best way to go. >> >> One more question: Passenger documentation says to touch >> tmp/restart.txt when you need to restart. Does Capistrano detect >> Passenger and do this automatically? Or do I need to add this to >> deploy.rb also? >> >> Thank you all for your help. >> >> -- >> Thomas ><> >> Raving Genius? - foaming at the brain? >> m: 919 449.6305 >> e: thomas at ravinggenius.com >> w: http://log.ravinggenius.com/ >> wii: 6751 1365 9898 2150 >> _______________________________________________ >> raleigh-rb-members mailing list >> raleigh-rb-members at rubyforge.org >> http://rubyforge.org/mailman/listinfo/raleigh-rb-members >> > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at hales.ws Fri Mar 13 15:10:31 2009 From: mike at hales.ws (Michael Hale) Date: Fri, 13 Mar 2009 15:10:31 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <49BA9D14.2000109@lojic.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <49BA9D14.2000109@lojic.com> Message-ID: <60190a730903131210s72e1ab76o835f0a5c39c0409f@mail.gmail.com> > Just out of curiosity, why do you have database.yml in .gitignore? Do > multiple people require their own, unique, non-prod settings? Personally I don't like to store any production secrets in my repository. That goes for database.yml s3.yml and even my session secret. http://github.com/red56/the-connected-website/blob/fc21dcc18ac53f52ff8fe569b87743acf02af172/config/environment.rb#L14 http://github.com/red56/the-connected-website/blob/fc21dcc18ac53f52ff8fe569b87743acf02af172/config/deploy/production.rb#L37 From info at lojic.com Fri Mar 13 15:38:25 2009 From: info at lojic.com (Brian Adkins) Date: Fri, 13 Mar 2009 15:38:25 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <60190a730903131210s72e1ab76o835f0a5c39c0409f@mail.gmail.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <49BA9D14.2000109@lojic.com> <60190a730903131210s72e1ab76o835f0a5c39c0409f@mail.gmail.com> Message-ID: <49BAB631.9090700@lojic.com> Michael Hale wrote, On 3/13/09 3:10 PM: >> Just out of curiosity, why do you have database.yml in .gitignore? Do >> multiple people require their own, unique, non-prod settings? > > Personally I don't like to store any production secrets in my > repository. That goes for database.yml s3.yml and even my session > secret. Sure, but you don't have to remove the entire file, just the secret stuff. You can execute erb in database.yml, so that opens quite a few options to get the secret. Pros/cons either way I suppose. -- Brian Adkins Lojic Technologies, LLC http://lojic.com/ 919-946-7547 (mobile) From thomas at ravinggenius.com Fri Mar 13 15:51:50 2009 From: thomas at ravinggenius.com (Thomas Ingram) Date: Fri, 13 Mar 2009 15:51:50 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <49BA9D14.2000109@lojic.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <49BA9D14.2000109@lojic.com> Message-ID: <51ce9ce10903131251l568d35ecld6ff09aeb1db301d@mail.gmail.com> It has database credentials. On Fri, Mar 13, 2009 at 1:51 PM, Brian Adkins wrote: > Just out of curiosity, why do you have database.yml in .gitignore? Do > multiple people require their own, unique, non-prod settings? -- Thomas ><> Raving Genius? - foaming at the brain? m: 919 449.6305 e: thomas at ravinggenius.com w: http://log.ravinggenius.com/ wii: 6751 1365 9898 2150 From mike at hales.ws Fri Mar 13 16:18:10 2009 From: mike at hales.ws (Michael Hale) Date: Fri, 13 Mar 2009 16:18:10 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <49BAB631.9090700@lojic.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <49BA9D14.2000109@lojic.com> <60190a730903131210s72e1ab76o835f0a5c39c0409f@mail.gmail.com> <49BAB631.9090700@lojic.com> Message-ID: <60190a730903131318m38d8d0f4w20263468f5d075df@mail.gmail.com> > Sure, but you don't have to remove the entire file, just the secret stuff. > You can execute erb in database.yml, so that opens quite a few options to > get the secret. Pros/cons either way I suppose. Hmm I hadn't thought about using erb on database.yml before. Interesting. From list-phi at moonshark.com Fri Mar 13 19:19:25 2009 From: list-phi at moonshark.com (Phi.Sanders) Date: Fri, 13 Mar 2009 19:19:25 -0400 Subject: [raleigh.rb] Noob deployment questions In-Reply-To: <60190a730903131318m38d8d0f4w20263468f5d075df@mail.gmail.com> References: <51ce9ce10903131027k70557b89hfadc26f83cf09c60@mail.gmail.com> <49BA9D14.2000109@lojic.com> <60190a730903131210s72e1ab76o835f0a5c39c0409f@mail.gmail.com> <49BAB631.9090700@lojic.com> <60190a730903131318m38d8d0f4w20263468f5d075df@mail.gmail.com> Message-ID: <0EC60ADD-B582-48F0-BA57-6282219B10D6@moonshark.com> On Mar 13, 2009, at 4:18 PM, Michael Hale wrote: >> Sure, but you don't have to remove the entire file, just the secret >> stuff. >> You can execute erb in database.yml, so that opens quite a few >> options to >> get the secret. Pros/cons either way I suppose. > > Hmm I hadn't thought about using erb on database.yml before. > Interesting. I've been deploying some non-repository config files, with Erb interpolation, via capistrano : require 'erb' template = File.read(local_template_path) erbed_data = ERB.new(template).result(binding) put( erbed_data, remote_destination_path, :mode => 0444) It's worked fine in my particular scenario for many months ~Phi From thomas at ravinggenius.com Sun Mar 15 19:05:08 2009 From: thomas at ravinggenius.com (Thomas Ingram) Date: Sun, 15 Mar 2009 19:05:08 -0400 Subject: [raleigh.rb] Noob deployment questions, part two Message-ID: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> Okay, so I have one more question. I have almost everything worked out with that first deploy I asked about earlier. (By the way thank you all for your help!) Anyway all static pages on my staging server work, but I'm getting an error message on any page that requires database access. production.log indicates that the database has no tables, which I was able to confirm this with MySQL Query Browser. The obvious (to me) solution was to log into my server, cd to the application's current directory and run rake db:schema:load. That looked like it worked, based on the output onscreen, but after restarting everything, I'm still getting the same error. I made sure that db/schema.rb has all the table information, and it does. I found a blog mentioning cap log_deploy, but Capistrano says that is not a valid task. Can anyone tell me what's going on? Why can't I migrate my schema? -- Thomas ><> Raving Genius? - foaming at the brain? m: 919 449.6305 e: thomas at ravinggenius.com w: http://log.ravinggenius.com/ wii: 6751 1365 9898 2150 From seancribbs at gmail.com Sun Mar 15 19:24:53 2009 From: seancribbs at gmail.com (Sean Cribbs) Date: Sun, 15 Mar 2009 19:24:53 -0400 Subject: [raleigh.rb] Noob deployment questions, part two In-Reply-To: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> References: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> Message-ID: <49BD8E45.4010502@gmail.com> And you ran 'rake db:schema:load RAILS_ENV=production' ? Sean Thomas Ingram wrote: > Okay, so I have one more question. I have almost everything worked out > with that first deploy I asked about earlier. (By the way thank you > all for your help!) Anyway all static pages on my staging server work, > but I'm getting an error message on any page that requires database > access. production.log indicates that the database has no tables, > which I was able to confirm this with MySQL Query Browser. The obvious > (to me) solution was to log into my server, cd to the application's > current directory and run rake db:schema:load. That looked like it > worked, based on the output onscreen, but after restarting everything, > I'm still getting the same error. I made sure that db/schema.rb has > all the table information, and it does. I found a blog mentioning cap > log_deploy, but Capistrano says that is not a valid task. > > Can anyone tell me what's going on? Why can't I migrate my schema? > > From thomas at ravinggenius.com Sun Mar 15 19:39:29 2009 From: thomas at ravinggenius.com (Thomas Ingram) Date: Sun, 15 Mar 2009 19:39:29 -0400 Subject: [raleigh.rb] Noob deployment questions, part two In-Reply-To: <49BD8E45.4010502@gmail.com> References: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> <49BD8E45.4010502@gmail.com> Message-ID: <51ce9ce10903151639o32e5cf00r180dc1067b832d96@mail.gmail.com> AHA! I was missing the 'RAILS_ENV=production' bit. Thanks a bunch! On Sun, Mar 15, 2009 at 7:24 PM, Sean Cribbs wrote: > And you ran 'rake db:schema:load RAILS_ENV=production' ? -- Thomas ><> Raving Genius? - foaming at the brain? m: 919 449.6305 e: thomas at ravinggenius.com w: http://log.ravinggenius.com/ wii: 6751 1365 9898 2150 From otto.hammersmith at gmail.com Sun Mar 15 20:31:20 2009 From: otto.hammersmith at gmail.com (Otto Hammersmith) Date: Sun, 15 Mar 2009 20:31:20 -0400 Subject: [raleigh.rb] Noob deployment questions, part two In-Reply-To: <51ce9ce10903151639o32e5cf00r180dc1067b832d96@mail.gmail.com> References: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> <49BD8E45.4010502@gmail.com> <51ce9ce10903151639o32e5cf00r180dc1067b832d96@mail.gmail.com> Message-ID: You can also deploy with cap deploy:migrations and it does the migrate for you at the end. cap deploy:migrate (verb not noun) will just do the migration without the deploy. On Sun, Mar 15, 2009 at 7:39 PM, Thomas Ingram wrote: > AHA! I was missing the 'RAILS_ENV=production' bit. Thanks a bunch! > > On Sun, Mar 15, 2009 at 7:24 PM, Sean Cribbs wrote: > > And you ran 'rake db:schema:load RAILS_ENV=production' ? > > -- > Thomas ><> > Raving Genius? - foaming at the brain? > m: 919 449.6305 > e: thomas at ravinggenius.com > w: http://log.ravinggenius.com/ > wii: 6751 1365 9898 2150 > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -------------- next part -------------- An HTML attachment was scrubbed... URL: From efg at ncsu.edu Sun Mar 15 22:16:25 2009 From: efg at ncsu.edu (Ed Gehringer) Date: Sun, 15 Mar 2009 22:16:25 -0400 Subject: [raleigh.rb] Student internships for summer? Message-ID: <375B2B61-E866-4E48-ADFE-AA65324891A9@ncsu.edu> I have four masters students who are working with me on a Ruby project this spring. Come summer, they will have had one semester's experience in Ruby. If anyone has or knows of work that might be available, please let me know, and I will pass it on. Thanks, Ed -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at hales.ws Mon Mar 16 08:29:19 2009 From: mike at hales.ws (Michael Hale) Date: Mon, 16 Mar 2009 08:29:19 -0400 Subject: [raleigh.rb] Noob deployment questions, part two In-Reply-To: References: <51ce9ce10903151605s1d244a78kff5d8f71c6542ccb@mail.gmail.com> <49BD8E45.4010502@gmail.com> <51ce9ce10903151639o32e5cf00r180dc1067b832d96@mail.gmail.com> Message-ID: <60190a730903160529s746ede8dof7ddad6ea9115be7@mail.gmail.com> If you want to always deploy with migrations you could re-write the default deploy task similar to how spacesuit has: http://github.com/ntalbott/spacesuit/blob/2ab45dcaee11caf53c2915ed87934a888b8da115/lib/spacesuit/recipes/common.rb On Sun, Mar 15, 2009 at 8:31 PM, Otto Hammersmith wrote: > You can also deploy with cap deploy:migrations and it does the migrate for > you at the end. > cap deploy:migrate (verb not noun) will just do the migration without the > deploy. > > On Sun, Mar 15, 2009 at 7:39 PM, Thomas Ingram > wrote: >> >> AHA! I was missing the 'RAILS_ENV=production' bit. Thanks a bunch! >> >> On Sun, Mar 15, 2009 at 7:24 PM, Sean Cribbs wrote: >> > And you ran 'rake db:schema:load RAILS_ENV=production' ? >> >> -- >> Thomas ><> >> Raving Genius? - foaming at the brain? >> m: 919 449.6305 >> e: thomas at ravinggenius.com >> w: http://log.ravinggenius.com/ >> wii: 6751 1365 9898 2150 >> _______________________________________________ >> raleigh-rb-members mailing list >> raleigh-rb-members at rubyforge.org >> http://rubyforge.org/mailman/listinfo/raleigh-rb-members > > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -- Michael Hale mikehale at gmail.com m: 919.961.7171 jabber: mikehale at gmail.com skype: mhale2243 From mark at 37signals.com Tue Mar 17 14:39:04 2009 From: mark at 37signals.com (Mark Imbriaco) Date: Tue, 17 Mar 2009 14:39:04 -0400 Subject: [raleigh.rb] Pre-Meeting Chow. Message-ID: As is traditional, a number of us will be getting together at Baja Burrito (http://tinyurl.com/2o2luk) at 5:30PM for pre-meeting sustenance. Anyone who wants to join us is more than welcome! -Mark -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2419 bytes Desc: not available URL: From michael at webadvocate.com Tue Mar 17 16:44:34 2009 From: michael at webadvocate.com (Michael Klett) Date: Tue, 17 Mar 2009 16:44:34 -0400 Subject: [raleigh.rb] Pre-Meeting Chow. In-Reply-To: References: Message-ID: ...and Shay and I (at least) are going to Sammy's (http://tinyurl.com/cpg4kt) afterwards for post-meeting hydration. Feel free to join us! 2009/3/17 Mark Imbriaco > > As is traditional, a number of us will be getting together at Baja Burrito > (http://tinyurl.com/2o2luk) at 5:30PM for pre-meeting sustenance. Anyone > who wants to join us is more than welcome! > > -Mark > _______________________________________________ > raleigh-rb-members mailing list > raleigh-rb-members at rubyforge.org > http://rubyforge.org/mailman/listinfo/raleigh-rb-members > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at ravinggenius.com Thu Mar 19 21:14:54 2009 From: thomas at ravinggenius.com (Thomas Ingram) Date: Thu, 19 Mar 2009 21:14:54 -0400 Subject: [raleigh.rb] View help (related selects) needed please Message-ID: <51ce9ce10903191814j3ae707e6t300f77c54ece52bf@mail.gmail.com> Introduction: (http://pastie.org/421626) I am building a simple contact form (to create Bookings). I need to collect Country, Province and some other miscellaneous items. Method One:(http://pastie.org/421630) On the simple side of things, I was just going to have two plain select elements, but the country kept getting in the way when I submitted. The error message was: NoMethodError in Bookings#create You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.inject Method Two: (http://pastie.org/421638) Then I thought I could get around this by combining the two selects using option_groups_from_collection_for_select. This works, and I don't have any error now, but the code is really snarly. I have to hand-code the select tags, I really don't know how to get the second parameter out of the View and neither :include_blank nor :prompt do anything (I didn't really research this one much.) Ideally the solution would be a fancy version of Method One. It would be cool to use jQuery to hide the Province select until a Country is chosen. Then AJAX the Province with appropriate choices. This cannot be as difficult as I'm making it, right? Incidentally I started to develop this application with Merb (so I could use DataMapper), but ended up converting to Rails because because I couldn't find enough documentation for form helpers :). Thanks a bunch! -- Thomas ><> Raving Genius? - foaming at the brain? m: 919 449.6305 e: thomas at ravinggenius.com w: http://log.ravinggenius.com/ wii: 6751 1365 9898 2150 From seancribbs at gmail.com Thu Mar 19 22:28:05 2009 From: seancribbs at gmail.com (Sean Cribbs) Date: Thu, 19 Mar 2009 22:28:05 -0400 Subject: [raleigh.rb] View help (related selects) needed please In-Reply-To: <51ce9ce10903191814j3ae707e6t300f77c54ece52bf@mail.gmail.com> References: <51ce9ce10903191814j3ae707e6t300f77c54ece52bf@mail.gmail.com> Message-ID: <49C2FF35.8090200@gmail.com> As to your nil error, my guess is that the validation is failing and neither @country nor @countries are populated, thus they are failing in the view. Regarding your UI issue, it seems to be a simple matter of showing and hiding the right elements, which you could do with a combination of a small amount of Javascript and/or CSS. Here's how I would tackle it: I usually use Prototype, but I'm sure there's something similar in jQuery. var hideProvinces = function(){ var country = $F('country_id'); if(country) { $('province_id').up().show(); $('province_id').select('option').invoke('hide'); $('province_id').select('option.country_'+country).invoke('show'); } else { $('province_id').up().hide(); } } $('country_id').observe('change', hideProvinces); This requires that you apply a class to your