tag:blogger.com,1999:blog-60552148340876642402024-03-13T12:14:33.353-07:00Rails Hacks and Other StuffRamonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.comBlogger68125tag:blogger.com,1999:blog-6055214834087664240.post-3144430326464789742010-04-15T00:11:00.000-07:002010-04-15T00:26:00.311-07:00Downloading filesWow it's been a year since I've last posted!<br /><br />I'm currently checking out dragonfly, the new kid on the block file processor. It's mean to replace stuff like paperclip and attachment_fu. To make things simple, especially if you don't have a lot of files, when migrating from either of those to dragonfly it may be simpler to just download the file and upload it again via dragonfly. This way you don't have to study the internals of each file management plugin.<br /><br />So, here's how to download a file.<br /><br />require 'net/http'<br /><br />url = URI.parse "http://url.to/file.name"<br />Net::HTTP.start url.host do |http|<br /> response = http.get url.path<br /> MyModel.create! :file => response.body <br /> # Here you tell your model to create the file. <br /> # This is what the create action in the controller calls <br /> # but instead of params[:file], you have response.body<br />endRamonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-59081291201826201232009-04-17T09:02:00.000-07:002009-04-17T09:04:02.108-07:00Vim SetupI've posted many a setup in vim before, but I've decided to put it <a href="http://github.com/ramontayag/vim_setup/tree/master">on github</a> for easier management.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-74596367157619833112009-04-01T05:06:00.000-07:002009-04-01T05:11:17.766-07:00Stars and acts_as_rateableI recently wanted to implement a star system in Rails. I looked at <a href="http://github.com/azabaj/acts_as_rateable/tree/master">this rateable plugin</a> and followed <a href="http://swik.net/Rails/Dave+Naffis+-+Rails,+Ruby,+Randomness/Ruby+on+Rails,+Ajax+&+CSS+Star+Rating+System/kqn0">this tutorial to create the stars</a>.<br /><br />It wasn't as cut and dried as I had hoped, so <a href="http://pastie.org/433706">here is the code I used</a>. It's pretty complete. Disclaimer: I used haml and sass and if you don't, you should still be able to understand the code. In case you don't use sass, here's <a href="http://pastie.org/433713">the generated CSS that you get from the sass file</a>.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-27635277212960989022009-03-27T22:13:00.000-07:002009-03-27T22:22:52.042-07:00before_create should return the right boolean!This is a small thing, but I wasted an hour or so figuring this thing out. I had an a before_create where I set a boolean variable to false and then my tests started to fail? Why? Because before_create will stop the creation of the record if it returns false!<br /><br /><pre><br />class A << AR::Base<br /> before_create :set_enabled<br /><br /> def set_enabled<br /> self.enabled = false<br /> true # so that it doesn't fail<br /> end<br />end<br /></pre>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-51853493138465605252009-03-20T22:46:00.000-07:002009-03-20T23:06:19.602-07:00Passenger, Monit, PostfixSetting up Passenger was quite easy, coming from the world of Mongrel. For the most part I followed <a href="http://hackd.thrivesmarthq.com/how-to-setup-a-linux-server-for-ruby-on-rails-with-github-and-phusion-passenger">this</a>. It's pretty comprehensive, but I'll just add some stuff that I had to do on my own.<br /><br />This is far from a comprehensive list, and if you just follow this things won't work. This also assumes you have _some_ knowledge of how Postfix, Monit, Linux works.<br /><br /><span style="font-size:180%;">Postfix</span><br />I accept and read mail somewhere else (not on the VPS that sends mail). For example, I may use Google to accept mail on the Internet, however, I don't connect my server to Google to send mail. Because of this, when postfix on my server tried to send mail to mydomain.com, it always something like "there is no user <insert> on this server". So I opened up /etc/postfix/main.cf and make sure that mydestination doesn't contain your domain name. mydestination tells postfix what resides on your local machine.<br /><br /><pre><br />mydestination = localhost.localdomain, localhost<br /></pre><br /><br />Also, to use it, my Rails app's setting were like this:<br /><pre><br /><span style="color: rgb(11, 83, 148);">ActionMailer::Base.delivery_method = :smtp<br />ActionMailer::Base.smtp_settings = {<br /> :address => "localhost",<br /> :port => 25,<br /> :domain => "www.theinksquad.com"<br />}</span><br /></pre><br /><br /><span style="font-size:180%;">SilverRack and Sources</span><br />Installing the clean 8.04 on SilverRack, /etc/apt/sources.list is virtually empty. You need to add:<br /><pre><br /><span id="pj4h1" style="color:#0b5394;"><span id="esyj" style="color: rgb(0, 0, 0);"><span id="bb-o0" style="color: rgb(11, 83, 148);">deb http://ubuntu.media.mit.edu/ubuntu/ hardy main restricted universe multiverse</span><br /><span id="bb-o2" style="color: rgb(11, 83, 148);">deb-src http://ubuntu.media.mit.edu/ubuntu/ hardy restricted main multiverse universe</span><br /><br /><span id="bb-o5" style="color: rgb(11, 83, 148);">deb http://ubuntu.media.mit.edu/ubuntu/ hardy-updates main restricted universe multiverse</span><br /><span id="bb-o7" style="color: rgb(11, 83, 148);">deb-src http://ubuntu.media.mit.edu/ubuntu/ hardy-updates restricted main multiverse universe</span><br /><br /><span id="bb-o10" style="color: rgb(11, 83, 148);">deb http://security.ubuntu.com/ubuntu/ hardy-security main restricted universe multiverse</span><br /><span id="bb-o12" style="color: rgb(11, 83, 148);">deb-src http://security.ubuntu.com/ubuntu/ hardy-security restricted main multiverse universe<br /></pre><br /><br />Then "sudo apt-get update" after<br /><br /><span style="font-size:180%;">Monit</span><br />The tutorial above didn't have any tutorial for Monit or God.rb. Install the dependencies first:<br /><pre><br /></span></span></span><span id="zids0" style="color:#0b5394;">sudo apt-get install flex byacc bison -y</span><br /><span id="pj4h1" style="color:#0b5394;"><span id="esyj" style="color: rgb(0, 0, 0);"><span id="bb-o12" style="color: rgb(11, 83, 148);"></pre></span></span></span><br /><br />Then monit (Make sure this is the latest and greatest version):<br /><pre><br /><span style="color: rgb(11, 83, 148);" id="r_zk0" >wget </span><span style="color: rgb(11, 83, 148);">http://mmonit.com/monit/dist/beta/monit-5.0_beta7.tar.gz</span><br /><span style="color: rgb(11, 83, 148);" id="r_zk0" >tar -xzvf </span><span style="color: rgb(11, 83, 148);">monit-5.0_beta7.tar.gz</span><span style="color: rgb(11, 83, 148);" id="r_zk0" > && cd </span><span style="color: rgb(11, 83, 148);">monit-5.0_beta7</span><span style="color: rgb(11, 83, 148);" id="r_zk0" >/ && sudo ./configure && sudo make && sudo make install && cd ../</span><br /><span id="zlzp87" style="color:#0b5394;"></span><span id="rxfr1" style="color:#0b5394;">sudo mkdir /etc/monit.d</span><br /></pre><br /><br />Then make the monit file for Apache. This file basically tells monit what to watch out for, and how.<br /><br />Sample /etc/monit.d/apache.monitrc<br /><span id="or6q" style="color:#000000;"><pre></span><br /><span style="color: rgb(11, 83, 148);">check process apache with pidfile /var/run/apache2.pid<br /> start program = "/etc/init.d/apache2 start"<br /> stop program = "/etc/init.d/apache2 stop"<br /> if cpu > 60% for 2 cycles then alert<br /> if cpu > 80% for 5 cycles then restart<br /> if totalmem > 200.0 MB for 5 cycles then restart<br /> if children > 250 then restart<br /> if loadavg(5min) greater than 20 for 8 cycles then alert<br /> group yourappnamehere</span><br /><span id="or6q" style="color:#000000;"></pre><br /><br /></span>Since I use workling, I also made a seperate file for it:<br /><span id="or6q" style="color:#000000;"><span id="or6q0" style="color:#0b5394;">server$ sudo vi /etc/<span style="color: rgb(11, 83, 148);" id="or6q1" >monit.d/workling.monitrc</span></span><br />and paste (do a "which ruby" to find out where ruby is and replace the /usr/bin/ruby if needed)<br /><pre><br /></span><span style="color: rgb(11, 83, 148);">check process workling with pidfile /var/www/</span><span style="color: rgb(11, 83, 148);">yourappname</span><span style="color: rgb(11, 83, 148);">/shared/log/workling.pid</span><br /><span style="color: rgb(11, 83, 148);"> start program = "/bin/bash -c 'HOME=/var/www/</span><span style="color: rgb(11, 83, 148);">yourappname</span><span style="color: rgb(11, 83, 148);">/current RAILS_ENV=production /usr/bin/ruby /var/www/</span><span style="color: rgb(11, 83, 148);">yourappname</span><span style="color: rgb(11, 83, 148);">/current/script/workling_client start'"</span><br /><span style="color: rgb(11, 83, 148);"> stop program = "/bin/bash -c '/usr/bin/ruby /var/www/</span><span style="color: rgb(11, 83, 148);">yourappname</span><span style="color: rgb(11, 83, 148);">/current/script/workling_client stop'"</span><br /><span style="color: rgb(11, 83, 148);"> if totalmem is greater than 180.0 mb for 5 cycles then restart</span><br /><span style="color: rgb(11, 83, 148);"> if cpu is greater than 90% for 5 cycles then restart</span><br /><span style="color: rgb(11, 83, 148);"> if 20 restarts within 20 cycles then timeout</span><br /><span style="color: rgb(11, 83, 148);"> group yourappname</span><br /><span id="or6q" style="color:#000000;"></pre></span><br /><br />Then reload monit via "sudo monit reload".<br /><br />Now monit needs to be told to start automatically when we startup and when/if it crashes, we'll use upstart (this is for Ubuntu only?)<span id="zlzp97" style="color:#000000;"><br /></span><pre><span style="color: rgb(11, 83, 148);"><span style="font-family: Georgia,serif;"><pre></span></span></pre> <span id="zlzp97" style="color:#000000;"><span id="cx6d0" style="color:#0b5394;">server$ sudo vi /etc/event.d/service_monit</span><br /></span><pre><span style="color: rgb(11, 83, 148);"><span style="font-family: Georgia,serif;"></pre></span></span></pre> <br /><span id="zlzp97" style="color:#000000;">and paste (do a "which monit" to find out where monit is and replace the /usr/local/bin/monit if needed)<br /></span><br /><pre><span style="color: rgb(11, 83, 148);"><span style="font-family: Georgia,serif;"><pre></span></span></pre><span style="color: rgb(11, 83, 148);"># This is an event.d (upstart) script to keep monit running</span><br /><pre><span style="color: rgb(11, 83, 148);"># To install disable the old way of doing things:</span><br /><span style="color: rgb(11, 83, 148);">#</span><br /><span style="color: rgb(11, 83, 148);"># /etc/init.d/monit stop && update-rc.d -f monit remove</span><br /><span style="color: rgb(11, 83, 148);">#</span><br /><span style="color: rgb(11, 83, 148);"># then put this script here: /etc/event.d/monit</span><br /><span style="color: rgb(11, 83, 148);">#</span><br /><span style="color: rgb(11, 83, 148);"># You can manually start and stop monit like this:</span><br /><span style="color: rgb(11, 83, 148);"># </span><br /><span style="color: rgb(11, 83, 148);"># start monit</span><br /><span style="color: rgb(11, 83, 148);"># stop monit</span><br /><span style="color: rgb(11, 83, 148);">#</span><br /><span style="color: rgb(11, 83, 148);"># Michael Hale (http://halethegeek.com)</span><br /><br /><span style="color: rgb(11, 83, 148);">start on startup</span><br /><span style="color: rgb(11, 83, 148);">start on runlevel 2</span><br /><span style="color: rgb(11, 83, 148);">start on runlevel 3</span><br /><span style="color: rgb(11, 83, 148);">start on runlevel 4</span><br /><span style="color: rgb(11, 83, 148);">start on runlevel 5</span><br /><br /><span style="color: rgb(11, 83, 148);">stop on runlevel 0</span><br /><span style="color: rgb(11, 83, 148);">stop on runlevel 6</span><br /><br /><span style="color: rgb(11, 83, 148);">exec /usr/local/bin/monit -Ic /etc/monit/monitrc</span><br /><span style="color: rgb(11, 83, 148);">respawn<span style="font-family: Georgia,serif;"><br /></pre><br /></span></span></pre>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-49629283739878724502009-03-18T00:49:00.000-07:002009-03-18T01:01:23.007-07:00Moving To Passenger, WorklingI've used backgroundrb for a while now. Coupled with mongrels, monit, it wasn't a pleasant experience. Oh, I forgot to mention that I was learning Linux at the time (still am actually), so it was very difficult for me.<br /><br />Lately, I've been comtemplating moving my production environment to Passenger, Apache, Workling and God. The next few posts will talk about my experience and what I did. :)<br /><br />For now, let me just say that this <a href="http://hackd.thrivesmarthq.com/how-to-setup-a-linux-server-for-ruby-on-rails-with-github-and-phusion-passenger">help page</a> played a big part in speeding up my staging.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-10173700008056984742009-03-03T23:35:00.000-08:002009-03-18T01:04:49.218-07:00Cleaning Up Your ActiveRecord SessionsI was looking for a way to do this and found a good resource to find out how (without coding it yourself!)<br /><br />http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails#sexpire refers to a plugin called limited session but the link is no longer valid. Check out http://iprog.com/project/limited_sessions<br /><br />Update: this breaks in Rails 2.3, I think it's because of the lazy loading. I've never learned much about sessions, so for now I'll move back to file stored.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-22576412424961143442009-02-17T17:57:00.000-08:002009-02-17T18:04:03.921-08:00View helpers in flashThe other day I wanted a nice checkout link in my flash when users added a product to their cart (apart from the checkout in cart area). I soon realized (or remembered) that you don't have access to view helpers in the controller, where you usually assign flash messages.<br /><br />I spent about 2 hours researching on how to do this but got no answer. People resorted to fancy stuff just to put links in their flash messages. I thought the answer was in the render method. I first tried to use it but it didn't work because you can't call render/redirect_to twice in the same action:<br /><br /><pre><br />flash[:notice] = render :partial => "some/partial"<br /></pre><br /><br />So I looked at the source and tried to figure out what it was in render that read the file and spat out the text. 10 minutes later, I got this to work:<br /><br /><pre><br />flash[:notice] = @template.render(:partial => "some/partial")<br /></pre><br /><br />So now I can use link_to and other nice view helpers in that partial and it will all render nicely in the flash message. :)Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-76570049060221720642009-02-12T21:59:00.000-08:002009-02-12T23:00:19.043-08:00Smart Activation With Single Sign OnThis post is related to another post of mine about <a href="http://railshacks.blogspot.com/2009/02/rpx-now-single-sign-on.html">getting the rpx single sign on to work</a>.<br /><br />Scenario:<br /><ul><li>You are using single sign on but require the user to have emails (Facebook does not return email) or require other fields (eg. accept terms of use).</li><li>You allow users to specify another email besides the one that is returned by the single sign on service (SSOS)<br /></li><li>If the user changes that email, you want them to validate it (you send an email to them with a link to activate their account), but if they don't change it (meaning they use the same email that is returned by the SSOS), then the account will be automatically activated</li></ul>For some reason, I did this the hard way at the beginning. I won't expound on how but what I tried to do in 2 days (but failed) actually took 30 minutes doing it the right way (and worked).<br /><br />Requisites<br /><ol><li>Make sure you got single sign on working (you're able to read responses and stuff)</li></ol>If you look at <a href="http://pastie.org/388014">my code</a> and read it a few times you'll understand what I do. From the RPX Controller, you render the login form so they have a chance to change stuff. If they miss out on anything the errors will render. If they submit it, then the form will be submitted to users/create and will render itself if they are still missing stuff. The hidden_field of email_was just stays there, dormant, waiting to be compared later on.<br /><br />When the user finally has all their stuff filled up and submits the form, if they're on single sign on, then the user will be activated based on the comparison between the email_was and the current email they're trying to save. If they're different, then they're not activated and the user observer sends out the activation mail. If they are the same email, then the account is activated and they have to do one less step. :)<br /><br />If you have any comments or suggestions please let me know.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-26044430415749938752009-02-08T00:52:00.000-08:002009-02-08T01:13:46.491-08:00Blocks in ViewI had a bunch of "if logged_in? && current_user.admin?" in my views, which made it very ugly. I saw an <a href="http://railscasts.com/episodes/40">old video</a> (it is also covered <a href="http://railscasts.com/episodes/140-rails-2-2-extras">again</a>) from <a href="http://railscasts.com/">Railscasts</a> and knew this would be my answer.<br /><br />However, I wanted more customization though. What if I didn't want to wrap my admin_area in a div? What if I wanted to add conditions on the fly and not make a zillion [enter_some_name]_area methods?<br /><br />This would be particularly useful if, for example, I only want the "delete" option of an object to appear to admins and if the object if destroyable.<br /><br />In haml:<br /><pre><br />- admin_area(:conditions => @object.destroyable?) do<br /> = link_to "Destroy", ...<br /></pre><br /><br />Take a look at my <a href="http://pastie.org/383089">helper method</a> to see what I did. I'd appreciate any comments!Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-1767153035942534022009-02-07T21:38:00.000-08:002009-02-07T21:49:58.444-08:00Form BuilderI don't know why I never know about Form Builder! I was making my own form helpers but in the completely stupid way - in the helper files, which made it clunky. Check out these <a href="http://tomek.codequest.eu/2008/12/28/how-to-write-a-custom-form-builder-in-rails/">two</a> <a href="http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder">posts</a> that helped me out a lot. Although it can seem complicated because of all the (what I think is) meta programming, I suggest you just dive in and explore.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-52977698013500089362009-02-06T04:07:00.000-08:002009-02-07T00:30:25.020-08:00RPX Now: Single Sign-onAs I write this, I'm trying to install the single sign-on capability that <a href="http://rpxnow.com/">RPX Now</a> gives you on my Rails app. I've tried OpenID before (using open_id_authentication plugin and ruby-openid gem) and it was mightly complicated, plus you couldn't only use other 3rd party accounts.<br /><br />RPX Now claims to be super easy and so far, with <a href="http://github.com/grosser/rpx_now/tree/master">grosser's rpx_now gem</a>, it almost seems too easy -- except there are no tutorials that I can find on Google. There are examples in gem's github site but they don't explain much.<br /><br />This is my attempt at writing one.<br /><br />First, install the gem (instructions in <a href="http://github.com/grosser/rpx_now/tree/master">the github site</a>). If you want to put it in your environment.rb file, it should look like this (remove or replace the version number with an updated one):<br /><pre>config.gem "grosser-rpx_now", :lib => "rpx_now", :version => "0.3", :source => "http://gems.github.com"<br /></pre>Then <a href="http://pastie.org/382369">create an RpxController</a> and add code similar to <a href="http://pastie.org/382369">this</a> to your user model. Of course, you don't have to process the data yourself, but I wanted to (thus my rpx_controller is a bit longer, and I had to read the response in the User model) so that if the rpx profile is missing anything, it will render a something like my normal login page that basically has a form_for(@user ...) where they can fill up the missing data.<br /><br />Check out <a href="http://pastie.org/382356">actual responses</a> (I just removed any personal data).Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com2tag:blogger.com,1999:blog-6055214834087664240.post-54439116837197789302009-02-06T04:04:00.000-08:002009-02-06T04:07:18.702-08:00Hosting ServicesI don't run websites with thousands of users at a time, however, I thought I'd still announce what I use for my hosting services.<br /><br />VPS: <a href="http://silverrack.com">SilverRack</a><br />Good price, quick service. They don't spend time fussing over you though, but that's expected in a VPS.<br /><br />Shared: <a href="http://www.hostingrails.com/home/3168727562">HostingRails</a> (disclaimer: affiliate link)<br />I've tried BlueHost, Dreamhost, but I've found HostingRails to be the easiest to deal with. Their support replies lightning fast, and don't diss you even if your problems are your fault!Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-69006354575197499142009-02-03T23:32:00.000-08:002009-02-03T23:47:54.262-08:00Using --trace; cucumber & machinist order of loading filesI followed <a href="http://itsignals.cascadia.com.au/?p=30">this tutorial</a> to easily use <a href="http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails">Cucumber</a> with a fixture replacement plugin called <a href="http://github.com/notahat/machinist/tree/master">Machinist</a>. It worked great on my desktop, but when I moved to my laptop, running rake features didn't work - an "uninitialized constant Sham" error popped up and I spent a day figuring it out.<br /><br />Although the context of this problem is Cucumber and Machinist (which includes Sham), this is a post that talks about using --trace when you run into problems similar to this.<br /><br />IF YOU'RE FAMILIAR WITH CUCUMBER & MACHINIST...<br />The problem occured partially because I put my blueprints.rb file where env.rb is. I believe cucumber loads everything there in alphabetical order (doesn't explain why my desktop loaded things differently). The problem is that blueprints.rb tries to call "Sham" which is something that is loaded by Machinist, which in turn is loaded during or after env.rb, not before.<br /><br />IF YOU'RE NOT FAMILIAR NEITHER CUCUMBER NOR MACHINIST...<br />The problem occured because of the order files were loaded. I do not know why files were loaded differently in my desktop vs the laptop, but what the heck -- I found the error by using --trace and actually read the big <a href="http://pastie.org/379188">bad ugly code</a> that rake conveniently hides from us.<br /><br />http://pastie.org/379188<br /><br />So the lesson is: actually read what --trace spits out! :)Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-77980614571331801682009-01-23T06:23:00.001-08:002009-01-23T06:27:38.316-08:00Speeding up emailing in testsI lived with the fact that my test ground to a halt when my tests ran code that had to send emails. It finally got so bad I started asking around about it.<br /><br />I knew about a method to <a href="http://kpumuk.info/ruby-on-rails/testing-mailers-with-rspec/">test ActionMailer</a> and not send out emails... and I thought: why not apply these to ActionMailer when it's in the test environment? I ran my tests with rspec. Check out <a href="http://pastie.org/368698">the pastie</a> to see the code.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-61670520801474751912008-10-21T00:01:00.000-07:002008-10-21T00:04:42.696-07:00RSpec, attachment_fuI've been looking for a solution to force RSpec tests to override the attachment_fu storage setting. Since I use s3, it was very inefficient when I'd run my tests because the assets would be saved in s3. Not only does it cost money, but it was very slow.<br /><br />After spamming #rubyonrails I finally got an answer from _martinS_. He told me to do something like this: http://pastie.org/296895 - and it worked! I hope this helps you guys.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-15356774926225671912008-09-28T09:56:00.000-07:002008-09-28T10:02:27.010-07:00Compiling Sphinx in UbuntuI had just watched Ryan Bates' <a href="http://railscasts.com/episodes/120">screencast on Sphinx</a> and I wanted to install it on Ubuntu. Took me a while to find out how, so here are my instructions. I'm on Ubuntu 8.04<br /><br />1. <a href="http://www.sphinxsearch.com/downloads.html">Download the latest realease</a>. It's 0.9.8 as of writing.<br />2. Install it with <a href="file:///home/ramon/sphinx-0.9.8/doc/sphinx.html#supported-system">their instructions</a>. I ran into a problem though - I have MySQL already but not the files Sphinx needs to install. If you ran into this problem, continue:<br />3. In console, type:<br /><pre><br />mysql_config --cflags<br /></pre><br />That will tell you the package you need to install.<br />4. Mine was libmysqlclient15-dev:<br /><pre><br />sudo apt-get install libmysqlclient15-dev<br /></pre><br />5. Try installing Sphinx again, it should work this time.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com5tag:blogger.com,1999:blog-6055214834087664240.post-15985261493069210342008-09-09T08:40:00.000-07:002008-09-09T08:41:56.019-07:00attachment_fu, Rails 2.1 and before_thumbnail_savedI was working on before_thumbnail_saved callback in Rails 2.1 and it seems it has changed! It didn't work with me anymore. At least my old code didn't.<br /><br />Apparently, you only pass the thumbnail into the loop.<br /><br />Read this <a href="http://www.nullislove.com/2008/07/29/attachment_fu-tip/">blog post</a> for details.Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com2tag:blogger.com,1999:blog-6055214834087664240.post-65518686155592397392008-09-05T07:23:00.000-07:002008-09-05T07:27:56.506-07:00Rake: Update or create images generated by attachment_fuDid you upload a bunch of images and find out that the new layout needs a new size of the photos, and you didn't specify this in the has_attachment line of your model?<br /><br />This happened to me, and I wanted an easy to way update all images in the database. I didn't test this with millions of records or anything, but if you want to fix this up please leave a comment.<br /><br />Notes:<br /><ul><li>To use, simply edit has_attachment line with the new thumbnail sizes you want.<br /></li><li>IdeaImage is the model that I want to update</li><li>parentless is a named_scope that gets only the IdeaImages whose parent_id's are null.<br /></li></ul><pre><br /> namespace :images do<br /> desc "Updates all the thumbnails of idea_images based on the thumbnails hash in the model"<br /> task(:update_idea_images => :environment) do<br /> IdeaImage.parentless.each do |i|<br /> #destroy the thumbnails first<br /> i.thumbnails.each { |thumbnail| thumbnail.destroy } if i.thumbnailable?<br /> #then recreate the thumbnails<br /> i.attachment_options[:thumbnails].each { |suffix, size| i.create_or_update_thumbnail(i.create_temp_file, suffix, *size) }<br /> end<br /> end<br /> end<br /></pre>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-71029584043682442562008-08-01T00:46:00.000-07:002008-10-01T20:26:45.998-07:00Installing the latest gVim and Vim in Ubuntu Hardy HeronI recently got a new computer and reinstalled Ubuntu and found out that my old post on how to install the latest gVim in Hardy Heron didn't work anymore. This is what I did to install the latest one. Thanks <a href="http://launchpadlibrarian.net/15444002/vim-build.txt">godlygeek</a>!<br /><br /><pre><br /><pre>sudo apt-get build-dep vim<br />sudo apt-get install build-essential devscripts fakeroot dpkg-dev<br />apt-get source vim<br />cd vim-7.1<br />(cd upstream/patches; python get_patches.py)<br />dch -v 1:7.1-138+1ubuntu4~$(whoami)1 "Updated with patches through $(ls upstream/patches | grep -v '\.py$' | tail -n 1)"<br />sed -i -e '/gvimtutor/d' -e "1idebian/tmp/usr/bin/gvimtutor\t\t\t\tusr/bin/" debian/vim-runtime.install.in<br />dpkg-buildpackage -rfakeroot -uc -b<br /></pre></pre>Having trouble viewing that? See the <a href="http://pastie.org/283368">pastie</a>.<br /><br />Now, you're supposed to have .deb files in the parent directory. I ran into a problem though in the last line. Here are the last few lines of output after running dpkg-buildpackage -rfakeroot -uc -b: http://pastie.org/246789<br /><br />To fix this, godlygeek asked me to edit vim-7.1/<span>debian/vim-runtime.<wbr>install.in and remove the line with gvimtutor in it. See my <a href="http://pastie.org/246791">vim-runtime.install.in file</a>.<br /><br />So I edited it (gedit </span>vim-7.1/<span>debian/vim-runtime.<wbr>install.in), then ran the last line (</span><pre>dpkg-buildpackage -rfakeroot -uc -b</pre> <span>in vim-7.1 directory again.<br /><br />I got the compiled *.deb files in the parent directory!<br /><br />To install them (note that your files will look different):<br /><pre><br /><span>sudo dpkg -i </span><span>vim-full_7.1-138+1ubuntu4~ramon1_all.deb<br /></span><span>sudo </span><span>dpkg -i vim-gui-common_7.1-138+1ubuntu4~ramon1_all.deb<br /></span><span>sudo </span><span>dpkg -i vim-runtime_7.1-138+1ubuntu4~ramon1_all.deb<br /></span><span>sudo </span><span>dpkg -i </span><span>vim-gnome_7.1-138+1ubuntu4~ramon1_i386.deb<br /></span></pre><br /></span>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-67065048044662857292008-07-27T20:35:00.000-07:002008-07-27T20:36:39.255-07:00gVim and placing scriptsIt seems that everytime I install gVim in Ubuntu the place to put scripts is different. If anyone can shed some light on this please let me know. The last time I installed it, I put the scripts in /usr/share/vim/vimcurrentRamonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-13845384448920608112008-06-11T07:08:00.000-07:002008-06-11T22:50:27.026-07:00config/initializers/new_rails_defaults.rb and problems with Rails 2.0.2<span style="font-size:100%;"><span><span style="font-family:Arial Black;">I was trying to debug a Rails 2.0.2 app that didn't work on HostingRails. I froze the gems in the vendor folder and stuff, so that couldn't be the problem. When I looked at the cPanel error log, I saw this:<br /><br /><pre><br />[Wed Jun 11 08:34:18 2008] [notice] mod_fcgid: process /home/royalpa/public_html/dispatch.fcgi(20133) exit(communication error), terminated by calling exit(), return code: 1<br />from /home/royalpa/site_files/royalpalm/config/initializers/new_rails_defaults.rb:5<br /></pre><br /><br />I never saw new_rails_defaults.rb before so I looked at it and looked at my older Rails apps. It wasn't there. I suppose it's there because when you do "rails appname" in hostingrails, it makes a Rails 2.1 skeleton. It thinks you're going to make a 2.1 app! Delete it and it should work.<br /></span></span></span>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0tag:blogger.com,1999:blog-6055214834087664240.post-38748765016223691092008-05-23T05:09:00.001-07:002008-08-01T01:41:32.480-07:00Ruby, Rails, Mongrel, Monit, Nginx on Ubuntu 7.10 Gutsy<h1 id="zb2u0"> Ubuntu 7.10 on SilverRack</h1>I used to have a tutorial here, and I had gotten the files from an existing server. I made it for myself. Since ezra posted making sure I wasn't violating any copyrights, I've decided to take it down, since I can't prove where those files were taken from.<span id="ft7i7"><span id="ft7i12"><e.notifier@dummy.com></e.notifier@dummy.com></span></span>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com1tag:blogger.com,1999:blog-6055214834087664240.post-353997695497574182008-05-11T01:16:00.000-07:002008-05-11T01:26:23.647-07:00Rails.vim breaks in Hardy HeronWell, Vim breaks when using rails.vim in Ubuntu 8.04 Hardy Heron. Took me a few days to decide to actually try and fix it and not downgrade back down to Gutsy.<br /><br />This post explains what you can do to fix this error. We'll upgrade to the latest Vim. Because the error is caused by an old version of Vim and rails.vim, you need to update it. You can read about it in this <a href="https://bugs.launchpad.net/ubuntu/+source/vim/+bug/219546">thread</a>. That was my starting point to find the fix.<br /><br />1) Download and install the latest version of Vim<br /><pre><br />svn co https://vim.svn.sourceforge.net/svnroot/vim/vim7<br />cd vim7<br />./configure --with-features=huge<br />sudo make<br />sudo make install<br /></pre><br />2) Install all the plugins and scripts again<br />3) If you use haml, when I downloaded the latest version today of the haml syntax script, I had some illegal carriage return errors. I had to open haml.vim then save it via<br /><pre><br />:w ++ff=unix<br /></pre>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com4tag:blogger.com,1999:blog-6055214834087664240.post-84873134748661616722008-03-22T23:56:00.001-07:002008-03-23T00:03:46.747-07:00GawingAttachableDo you want to be able to attach files to something? I needed to do that today and I made a plugin called Gawing Attachable (translated: make_attachable). It allows you to add attachments to something you make attachable.<br /><br />Yes, there are many things you can still do to this, but like they say: make something quick and fix it up later on.<br /><br />Check out the README before installing.<br /><pre>script/plugin install http://lucidph.dreamhosters.com/gawing_attachable/trunk<br /></pre>Ramonhttp://www.blogger.com/profile/16360440870111079337noreply@blogger.com0