<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6420451017344231073</id><updated>2011-11-27T16:27:05.410-08:00</updated><category term='string'/><category term='ruby'/><category term='linux'/><category term='many-to-many'/><category term='Ruby on rails'/><category term='rubybrain.com'/><category term='factory girl'/><category term='gemsonrails'/><category term='rails'/><category term='index'/><category term='associations'/><category term='linode'/><category term='heroku'/><category term='herokugarden'/><category term='ubuntu'/><category term='gems'/><category term='join tables'/><category term='railsbrain.com'/><category term='multiple'/><title type='text'>Rails on Dave</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6420451017344231073.post-4774601327728919107</id><published>2009-06-18T03:39:00.000-07:00</published><updated>2009-06-18T04:02:41.714-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='linode'/><category scheme='http://www.blogger.com/atom/ns#' term='ubuntu'/><title type='text'>Configuring an Ubuntu server on linode, loaded with rails</title><content type='html'>Here's a short how-to for getting rails deployed on your linode server.&lt;br /&gt;1. log in to linode&lt;br /&gt;2. generate a public/private key pair on your own system if you havent done so already&lt;br /&gt;3. Click "Deploy a Linux Distribution"&lt;br /&gt;4. Choose one of the Ubuntu releases because I said so&lt;br /&gt;5. leave the defaults&lt;br /&gt;6. choose a root password&lt;br /&gt;7. click "create profile"&lt;br /&gt;8. click "boot" then "ok" on the popup&lt;br /&gt;9. click "console"&lt;br /&gt;10. copy your public key to the text field at the bottom (on one line plz) and click "submit keys to host."&lt;br /&gt;(if you're having trouble finding your public key, do a 'locate *.pub' at a command prompt)&lt;br /&gt;11.  Copy the text on the same page that should look something like this: '&lt;b&gt;&lt;code&gt;ssh linode22231@newark78.linode.com'&lt;br /&gt;&lt;/code&gt;&lt;/b&gt;12.  go to a command prompt (assuming you have ssh installed), enter what you copied and if you pasted your public key correctly in step 10, you should see: 'login:' or something to that effect. &lt;br /&gt;13.  Type in 'root' and enter&lt;br /&gt;14.  Type in your pass and enter&lt;br /&gt;15.  take a break&lt;br /&gt;16.  Type in 'apt-get update' to get the latest package lists&lt;br /&gt;17.  Type in 'sudo apt-get install gcc'&lt;br /&gt;18.  Type in 'sudo apt-get install ruby'&lt;br /&gt;&lt;br /&gt;ok, thats a good start...&lt;br /&gt;I'll be back with more later.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420451017344231073-4774601327728919107?l=railsondave.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/4774601327728919107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsondave.blogspot.com/2009/06/configuring-ubuntu-server-on-linode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/4774601327728919107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/4774601327728919107'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/2009/06/configuring-ubuntu-server-on-linode.html' title='Configuring an Ubuntu server on linode, loaded with rails'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420451017344231073.post-5379822096216769302</id><published>2009-06-17T18:22:00.000-07:00</published><updated>2009-06-17T18:26:42.748-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='railsbrain.com'/><category scheme='http://www.blogger.com/atom/ns#' term='rubybrain.com'/><title type='text'>railsbrain.com</title><content type='html'>A friend of mine at work pointed me to this gem of a site: &lt;a href="http://railsbrain.com"&gt;railsbrain.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It has the full rails api with a very nice interface.  Also, there's one for just ruby:  &lt;a href="http://rubybrain.com"&gt;rubybrain.com&lt;/a&gt;.  Check them out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420451017344231073-5379822096216769302?l=railsondave.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/5379822096216769302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsondave.blogspot.com/2009/06/railsbraincom.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/5379822096216769302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/5379822096216769302'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/2009/06/railsbraincom.html' title='railsbrain.com'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420451017344231073.post-2477848492396725387</id><published>2009-05-23T07:17:00.000-07:00</published><updated>2009-05-24T10:26:56.705-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='factory girl'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on rails'/><category scheme='http://www.blogger.com/atom/ns#' term='join tables'/><category scheme='http://www.blogger.com/atom/ns#' term='associations'/><category scheme='http://www.blogger.com/atom/ns#' term='many-to-many'/><title type='text'>Creating 'has_many :through' factories with Factory Girl</title><content type='html'>Factory girl is a great tool for setting up your database for testing.  However, I had some trouble when setting up an application that utilizes has_many, :through associations in the models.  How do you set up the factories for the two parents and the join table that has its own attributes and still maintain the connection between all three tables?  After a couple of days, I solicited the factory_girl list and Josh Clayton pointed me in the right direction, (thanks Josh!)&lt;br /&gt;&lt;br /&gt;BTW, I borrowed this particular application from http://www.jumbabox.com/2008/06/ruby-on-rails-many-to-many-tutorial/ if you need more explanation on the models used in this example.&lt;br /&gt;&lt;br /&gt;On to the solution:&lt;br /&gt;Here are the models:&lt;span style="font-family: monospace;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockqoute&gt;&lt;pre&gt;&lt;br /&gt;class Album &lt; ActiveRecord::Base&lt;br /&gt;  has_many :features&lt;br /&gt;  has_many :artists, :through =&gt; :features&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class Artist &lt; ActiveRecord::Base&lt;br /&gt;  has_many :features&lt;br /&gt;  has_many :albums, :through =&gt; :features&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class Feature &lt; ActiveRecord::Base&lt;br /&gt;  belongs_to :album&lt;br /&gt;  belongs_to :artist&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;/blockqoute&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;As you can see, the Artist and Album models are the parents and the Feature model is the join table.  This produces the desired many-to-many association with 'has_many /(:artists|:albums)/, :through =&gt; :features'.&lt;br /&gt;&lt;br /&gt;Here are the factories... There are two big concepts that should be mentioned that allow this association to be created properly.  For one, the associations in the factories should be created &lt;span style="font-weight: bold;"&gt;from the join table back to the parents&lt;/span&gt;.  This enables the parents' records to be created at the same time that the join table is created with the link between the three intact.&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;/code&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;# revised factories&lt;br /&gt;# created the associations from the join table only&lt;br /&gt;Factory.define(:artist) do |artist|&lt;br /&gt;  artist.name     "FooFighters"&lt;br /&gt;end&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Factory.define(:album) do |album|&lt;br /&gt;  album.name "FooTime"&lt;br /&gt;  album.genre "FooRock"&lt;br /&gt;  album.description "A good time"&lt;br /&gt;end&lt;br /&gt;&lt;/p&gt;# join table factory - :feature&lt;br /&gt;Factory.define(:feature) do |feature|&lt;br /&gt;  feature.association :artist&lt;br /&gt;  feature.association :album&lt;br /&gt;end &lt;pre&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;The second big concept is that wherever you create your factories (in my case, I'm using cucumber and create the factories in './features/support/env.rb') the parents factories are only @instantiated and returned, though not written to the database.  This is done using the 'Factory.build(:factory_name)' method rather than the Factory(:factory_name) or Factory.create(:factory_name) methods.  If you used create you would save multiple records to the database with no associations to the join table.  When the join table factory is 'create'd, the associations that were defined in the join table factory to the parents create the associated parent's records for you.&lt;br /&gt;&lt;br /&gt;Here is how I create the factories in ./features/support/env.rb (NOTE: these factories are created in a Before block that kills all data in the database tables because we want to reset the database as we aren't using transactional fixtures, then reconstructs them with the factories):&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Before do&lt;br /&gt;  #killing the table data as we aren't using fixtures&lt;br /&gt;  Album.destroy_all&lt;br /&gt;  Artist.destroy_all&lt;br /&gt;  Feature.destroy_all&lt;br /&gt;  #recreating the data&lt;br /&gt;  # **** Here's the magic ****&lt;br /&gt;  # building the parent factories first, and saving them&lt;br /&gt;  #  through the join table so that the&lt;br /&gt;  #    the join table record is fully created in db.&lt;br /&gt;  album = Factory.build(:album)&lt;br /&gt;  artist = Factory.build(:artist)&lt;br /&gt;  # using create here as the join table is written to&lt;br /&gt;  #    the db first with id's from album and artist factories.&lt;br /&gt;  #       you could use 'feature = Factory(:feature)'&lt;br /&gt;  #          though using 'create' method for clarity.&lt;br /&gt;  feature = Factory.create(:feature)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt; &lt;/blockquote&gt;This produces the following output from 'RAILS_ENV=test script/console':&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;Loading test environment (Rails 2.3.2)&lt;br /&gt;&gt;&gt; @feature = Feature.find(:all)&lt;br /&gt;=&gt; [#Feature id: 8, artist_id: 10, album_id: 8, number_of_songs: nil,&lt;br /&gt;created_at: "2009-05-23 15:03:25", updated_at: "2009-05-23 15:03:25"]&lt;br /&gt;&gt;&gt; @artist = Artist.find(:all)&lt;br /&gt;=&gt; [#Artist id: 10, name: "FooFighters", created_at: "2009-05-23 15:03:25",&lt;br /&gt;updated_at: "2009-05-23 15:03:25"]&lt;br /&gt;&gt;&gt; @album = Album.find(:all)&lt;br /&gt;=&gt; [#Album id: 8, genre: "FooRock", name: "FooTime", description: "A good time",&lt;br /&gt;created_at: "2009-05-23 15:03:25", updated_at: "2009-05-23 15:03:25"]&lt;br /&gt;&gt;&gt;&lt;br /&gt;&lt;feature&gt;&lt;artist&gt;&lt;album&gt;&lt;/album&gt;&lt;/artist&gt;&lt;/feature&gt;&lt;/pre&gt;&lt;feature style="font-weight: bold;"&gt;&lt;artist style="font-weight: bold;"&gt;&lt;album style="font-weight: bold;"&gt;&lt;/album&gt;&lt;/artist&gt;&lt;/feature&gt;&lt;/blockquote&gt;Great Success!&lt;br /&gt;&lt;br /&gt;I hope that was clear... hit me up if you are still having trouble with this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;script-console-output&gt;&lt;artist foofighters="" 22="" 01=""&gt;&lt;artist foofighters="" 22="" 01=""&gt;&lt;album foorock="" footime="" a="" good="" time="" 22="" 01=""&gt;&lt;album foorock="" footime="" a="" good="" time="" 22="" 01=""&gt;&lt;sqlite3-output&gt;&lt;/sqlite3-output&gt;&lt;/album&gt;&lt;/album&gt;&lt;/artist&gt;&lt;/artist&gt;&lt;/script-console-output&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420451017344231073-2477848492396725387?l=railsondave.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/2477848492396725387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsondave.blogspot.com/2009/05/creating-hasmany-through-factories-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/2477848492396725387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/2477848492396725387'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/2009/05/creating-hasmany-through-factories-with.html' title='Creating &apos;has_many :through&apos; factories with Factory Girl'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420451017344231073.post-3827124048839411117</id><published>2009-03-15T18:06:00.000-07:00</published><updated>2009-03-15T18:45:19.735-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='multiple'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><title type='text'>Variation on index method from Class String</title><content type='html'>Ok, so I wanted to find the indices of all occurrences of String 'A' within a larger String 'B'.  The Ruby core &lt;a href="http://www.ruby-doc.org/core/classes/String.html#M000799"&gt;String class's index&lt;/a&gt; and rindex methods do this for one value, but not for all of them.&lt;br /&gt;&lt;br /&gt;A recursive solution made the most sense (note: ternary operator has to be on one line):&lt;br /&gt;&lt;pre&gt;def indices(str, pos = 0)&lt;br /&gt;!self.index(str, pos).nil? /&lt;br /&gt;  ? (self.indices(str, self.index(str, pos)  + 1) /&lt;br /&gt;  | [].push(self.index(str, pos))).sort : []&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;That gives an array of all of the indices  in sorted order, and is actually quite cryptic.  Here's a more readable version:&lt;br /&gt;&lt;pre&gt;def indices(str, pos = 0)&lt;br /&gt; if (!self.index(str, pos).nil?)&lt;br /&gt;    # Get the position of the current find&lt;br /&gt;    x = self.index(str, pos)&lt;br /&gt;    # Return the union of what you found&lt;br /&gt;    #     and look for more occurrences&lt;br /&gt;    [].push(x) | self.indices(str, x + 1)&lt;br /&gt; else&lt;br /&gt;    # Basecase.  Return empty array for union "|"&lt;br /&gt;    []&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420451017344231073-3827124048839411117?l=railsondave.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/3827124048839411117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsondave.blogspot.com/2009/03/variation-on-index-method-from-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/3827124048839411117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/3827124048839411117'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/2009/03/variation-on-index-method-from-class.html' title='Variation on index method from Class String'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6420451017344231073.post-8675715812504513575</id><published>2009-03-01T19:41:00.000-08:00</published><updated>2009-03-05T15:43:07.892-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='herokugarden'/><category scheme='http://www.blogger.com/atom/ns#' term='gemsonrails'/><category scheme='http://www.blogger.com/atom/ns#' term='gems'/><category scheme='http://www.blogger.com/atom/ns#' term='heroku'/><title type='text'>Heroku gem deployment last resort</title><content type='html'>If you're having problems installing a gem in your heroku app, check this out as a last resort:&lt;br /&gt;&lt;br /&gt;Here's the workaround (commands in bold):&lt;br /&gt;1.) Get a local copy of your app by using the export option on heroku.&lt;br /&gt;2.) Unpack it to a local folder and open up a command line/shell/command prompt.&lt;br /&gt;3.) &lt;span style="font-weight: bold;"&gt;cd&lt;/span&gt; to your app's directory&lt;br /&gt;4.) &lt;span style="font-weight: bold;"&gt;gem install gemsonrails&lt;/span&gt; to get gemsonrails installed to your local gem repo&lt;br /&gt;5.) &lt;span style="font-weight: bold;"&gt;gemsonrails&lt;/span&gt; to install some gemsonrails helpers to your app's environment&lt;br /&gt;5.) &lt;span style="font-weight: bold;"&gt;rake gems:install GEM=&lt;nameofyourgem style="font-weight: bold;"&gt;&lt;/nameofyourgem&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;gem_you_want&lt;/span&gt; -&gt; gets your gem from the gem cloud in the sky and places it in vendor/gems&lt;br /&gt;6.) &lt;span style="font-weight: bold;"&gt;rake gems:freeze GEM=&lt;nameofyourgem style="font-weight: bold;"&gt;&lt;/nameofyourgem&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;gem_you_want&lt;/span&gt; -&gt; gets your gem ready for primetime&lt;br /&gt;7.) &lt;span style="font-weight: bold;"&gt;tar czf myapp.tar.gz myapp/&lt;/span&gt;&lt;br /&gt;8.) upload the tar.gz to heroku&lt;br /&gt;9.) sigh with relief because you can now use your favorite gem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6420451017344231073-8675715812504513575?l=railsondave.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://railsondave.blogspot.com/feeds/8675715812504513575/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsondave.blogspot.com/2009/03/heroku-gem-deployment-fun-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/8675715812504513575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6420451017344231073/posts/default/8675715812504513575'/><link rel='alternate' type='text/html' href='http://railsondave.blogspot.com/2009/03/heroku-gem-deployment-fun-with.html' title='Heroku gem deployment last resort'/><author><name>Dave Rogers</name><uri>http://www.blogger.com/profile/03159006525227734356</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
