The to_sentence method is nothing terribly new – just another reason why one would want to work with Ruby on Rails:
irb(main):005:0> require 'rubygems' => true irb(main):006:0> require 'activesupport' => true irb(main):007:0> ['John', 'Paul', 'George', 'Ringo'].to_sentence => "John, Paul, George, and Ringo"
As this has never worked right out of the box (the necessary files are in places not expected by the gem installer), here is what I do:
sudo gem install mysql -- --with-mysql-config=/usr/lib/mysql/mysql_config
In this nice blog entry is some description of how to make rails work with passenger on site5. As I liked to have Sinatra working for myself (and had the sinatra and rack gems installed locally), here is how it works for me:
- As usual with rails apps, have a symlink point from within $HOME/public_html to the public folder of your sinatra app.
- Create a .htaccess file in the same public directory, looking like
PassengerEnabled on RackBaseURI /linkname
which certainly means that you have to put in the name of the symlink
- Create a config.ru file in the app root
ENV['GEM_PATH'] = "#{ENV['HOME']}/gems:/usr/lib/ruby/gems/1.8" ENV['GEM_HOME'] = "#{ENV['HOME']}/gems" require 'rubygems' require 'sinatra' set :env, :production disable :run require 'app'The only significant change to a plain config.ru is the addition of the GEM_PATH at the very top of the file – this way your locally installed gems are being picked up by passenger
One more thing: it turned out to be a good idea to include the ENV['GEM_PATH'] = “#{ENV['HOME']}/gems:/usr/lib/ruby/gems/1.8″ line on top of the rails application file as well. Without that, starting a fresh passenger fork will cause an exception – it will however work on the second attempt. Will have to look into this …
As part of a Sinatra project, I gave Haml a try. The What is it section promises (among a number of technical aspects) positive feelings galore, which I was a little sceptical about:
Give yourself 5 minutes to read the Tutorial and then go convert one of your RHTML templates to Haml. Feel the power of the “DELETE” key. Simplify. Enjoy. Laugh. 20 minutes later, you will never go back.
But after having converted all of my erb templates in about 45 minutes, I was indeed smiling. Try it yourself!
Ok, this was easy. Some googling revealed the reason that none of my generated rspec tests would ever be picked up by autotest. You apparently have to export RSPEC=true in your shell, prior to starting autotest. So here is the getting started list:
- Install gems rspec, rspec-rails, ZenTest, redgreen
- generate scafffolds/models/controllers with the rspec method (installing the gems gives you, among others, the additional generator targets rspec_controller, rspec_model, rspec_scaffold)
- export RSPEC=true and start autotest
One quote from my first autotest run:
Finished in 0.963479 seconds
400 examples, 400 failures
While being all convinced of and impressed with all the advantages of developing with RSpec, cucumber and autotest, I have yet to find the time to actually start doing it. And there is not that much information out there (the bigger pieces probably being the screencasts on peepcode.com). I will try and document some of the more interesting findings as a convert. Right now, my rails project has reached its first milestone and is (or appears to be) functionally stable. Even if this was the case (which I do not really believe), keeping it that way would be worth writing tests.
Just in case you have not noticed yet: www.nomedojogo.com. The pdf file is a “What’s new in RoR 2.1″ compilation, thankfully often times being more elaborate than the usual bullet lists. Thanks!
is “The Rails Way” by Obie Fernandez. Trying to learn RoR in my spare time over the past 12 months, I have to say that it is a lot of fun and easy to learn (as the frameworks advocates say) and that it can be hard for beginners sometimes, as the critics claim. This is the most readable reference book I have seen so far, it covers Rails 2 and on several occasions I was able to solve problems by looking them up in the book. Money well spent, probably too much details for the absolute beginner.
The example on custom textile tags, given at the nubyonrails page is very well written, but left some individuals with the question, how to do custom inline tags. After some searching I found at least one reference in some forum, which I used to build the following code. What would one need a custom inline tag for, you might ask? In my case, I wanted a very simple way of referring to pages in a RoR mini-CMS I had built. To make abbreviated link names possible, a search action seemed appropriate. This means that something like ?"Lot 5"? would translate into <a href=”/titlesearch?searchterm=Lot 5″>Lot 5</a>. Using a class extending RedCloth already, all I had to do was to add the following lines of code:
RULES = [:inline_textile_search, :refs_textile, :block_textile_table,
:block_textile_lists, :block_textile_prefix, :inline_textile_image,
:inline_textile_link, :inline_textile_code, :inline_textile_span,
:glyphs_textile ]
# render internal links as title search links
def inline_textile_search(text)
text.gsub!(/(?"?)([w|s]+?)("?)/) do |m|
content = $~[2]
"<a href="/titlesearch?searchterm=#{content}">#{content}</a>"
end
end
def to_html
super(*RULES)
end
I should mention that this solution is far from being perfect (I am overwriting the RULES, taken from the current version of RedCloth, to add my tag method). At the same time, it works the way I wanted it to.
Some time ago, I did my first steps using capistrano for rails deployments. The requirement of a publicly accessible subversion repository seemed rather unmanageable, but I decided tor give it a try on our bluehost account. As there is a number of such tutorials out there, none of them completely worked for me – so here is my version. For all this you need to be logged in via ssh:
cd
mkdir -p svn/src
cd $HOME/svn
wget http://subversion.tigris.org/downloads/subversion-1.4.6.tar.gz
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.6.tar.gz
tar xzf subversion-1.4.6.tar.gz -C src
tar xzf subversion-deps-1.4.6.tar.gz -C src
cd $HOME/svn/src/subversion-1.4.6/
export CFLAGS=”-fPIC”
./configure –prefix=$HOME/svn –without-berkeley-db –with-zlib –with-ssl –with-expat=builtin
make
make install
This will install the entire subversion distribution in your $HOME/svn folder. After adding these lines to your $HOME/.bashrc you should be all set:
export PATH=”$PATH:$HOME/svn/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/svn/lib
After creating a repository (I’d go for something like svnadmin create $HOME/svn/repo), and configuring some user in there, you can access it from anywhere using something like this:
svn list svn+ssh://USERNAME@HOSTNAME/home/USERNAME/svn/repo
As such action will have to spawn an svnserve process each time you trigger it, do not expect great performance here. But it does work.
P.S.: If you’d wonder about the CFLAG export up there: not setting this, you might end up seeing the following error:
relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC