<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>redconfettiRuby on Rails | redconfetti</title>
	<atom:link href="http://www.redconfetti.com/category/web-dev/rails-web-dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redconfetti.com</link>
	<description>the journal of maxwell keyes</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:04:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rails 3 on WHM / cPanel VPS Server</title>
		<link>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/</link>
		<comments>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 17:14:58 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[cpanel]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails3.1]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=998</guid>
		<description><![CDATA[cPanel is working towards making Rails 3 applications run natively with Passenger, setup via the cPanel interface. I&#8217;m not really sure if this will be ideal, as most organizations deploy their apps to the server using Capistrano, not uploading via FTP or something. I&#8217;ve been hosting a number of PHP driven sites, including this blog,...]]></description>
			<content:encoded><![CDATA[<p>cPanel is <a href="http://forums.cpanel.net/f145/mod_rails-passenger-instead-mongrel-rails-3-support-case-44197-a-152577-p3.html" target="_blank">working towards making Rails 3 applications run natively</a> with Passenger, setup via the cPanel interface. I&#8217;m not really sure if this will be ideal, as most organizations deploy their apps to the server using Capistrano, not uploading via FTP or something.</p>
<p>I&#8217;ve been hosting a number of PHP driven sites, including this blog, from a shared hosting service for quite a while now. Shared hosting is fine for personal websites or even small businesses with 4-5 page brochure style websites that do not receive lots of traffic, but they&#8217;re not fine if slow performance or intermittent downtime causes you to loose business (or even the respect of your visitors). In such cases I recommend a VPS, because you control who you&#8217;re hosting and thus can ensure optimal uptime and performance. I highly recommend <a href="http://www.linode.com/" target="_blank">Linode</a> as a VPS provider.</p>
<p>I&#8217;ve been using the shared hosting for PHP/Wordpress sites, and a VPS to host the Ruby on Rails applications I&#8217;ve been working on. Really this is expensive, so I&#8217;m wanting to consolidate to one VPS for everything.</p>
<p>I&#8217;ve been forewarned that cPanel does things it&#8217;s own way, so if you&#8217;re trying to do something out-of-the-box you can run into issues. I&#8217;m aware of this, and through this article will let you know if setting up a Rails 3.1.3 hosting environment is possible with a WHM / cPanel server (RELEASE version 11.30.5, build 3). I plan on using Gitosis under an account to host repositories, Capistrano for deployment, and Passenger with Apache2 already provided by cPanel.</p>
<h2>Installing Ruby</h2>
<p>To stay within the &#8220;box&#8221; of the cPanel environment, I installed Ruby using the script provided by cPanel </p>
<pre class="brush:shell">
/scripts/installruby
</pre>
<h2>Gitosis</h2>
<p>To setup Gitosis you have to first install Python tools.</p>
<pre class="brush:shell">
yum -y install python-setuptools
</pre>
<p>Next, to install Git, you&#8217;ll have to use a special command because cPanel has configured /etc/yum.conf to exclude certain packages, including perl packages, so that they do not break or conflict with the cPanel system. Use the following command to install Git:</p>
<pre class="brush:shell">
yum --disableexcludes=main install git
</pre>
<p>From the root home directory, download and install Gitosis.</p>
<pre class="brush:shell">
cd /root
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
</pre>
<p>Next create an account to host your Git repositories from the WHM interface. I&#8217;ve added a user with the user name &#8216;git&#8217;, and used &#8216;git.web-app-host.com&#8217; as the domain (a subdomain under my hosting service domain). Set the password to a very long secure password. You won&#8217;t be needing it again, as you&#8217;ll be using an SSH key to authenticate.</p>
<p>After you&#8217;re done creating the cPanel account which will host the repositories, copy your public key from your local machine to your root users home direcotry ( /root/ ).</p>
<pre class="brush:shell">
scp ~/.ssh/id_rsa.pub root@vps.web-app-host.com:/root
</pre>
<p>Go back to your SSH session as &#8216;root&#8217; on the server and run this command to initialize the Gitosis repository under the &#8216;git&#8217; user account.</p>
<pre class="brush:shell">
root@vps [~]# sudo -H -u git gitosis-init < /root/id_rsa.pub
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
</pre>
<p>NOTE: Do not use the 'Manage SSH Keys' option from the cPanel for the Git acccount, as this will remove the Gitosis-admin repository key from /home/git/.ssh/authorized_keys.</p>
<p>Run the following command to make sure the post-update hook is executable. If this isn't done, then tasks performed by Gitosis after you commit an update aren't performed (i.e. creating new repositories).</p>
<pre class="brush:shell">
sudo chmod u+x /home/git/repositories/gitosis-admin.git/hooks/post-update
</pre>
<p>On your local machine, run the following command to clone the Gitosis-admin repository, used to manage your repositories on the server, to your local machine.</p>
<pre class="brush:shell">
git clone git@<YOURSERVER>:gitosis-admin.git
</pre>
<p>This should look like this:</p>
<pre class="brush:shell">
$ git clone git@vps.web-app-host.com:gitosis-admin.git
Cloning into 'gitosis-admin'...
stdin: is not a tty
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.
</pre>
<hr />
Note: If you are prompted for a password when running this clone command, you likely have some sort of SSH configuration not setup properly on your local machine. If you're using multiple keys with various hosts, check ~/.ssh/config and make sure you're using the proper syntax. Run 'ssh git@<YOURSERVER> -v' to get a verbose output of what's happening when the SSH session is initialized to investigate further.</p>
<hr />
<p>On the remote machine, go ahead and delete your public key from the root users home directory.</p>
<pre class="brush:shell">
rm /root/id_rsa.pub
</pre>
<p>After cloning the Gitosis repository to your local machine, you simply modify and commit changes to the 'gitosis.conf' file inside of the 'gitosis-admin' folder.</p>
<p>If you're configuring new users, simply add their public SSH keys to the 'keydir' folder with the '.pub' file extension. Refer to these users using the filename of the public key file without the '.pub' extension.</p>
<p>For instance I've added a repository called 'marketsim', and then added 'marketsim' to the 'writable' setting for the gitosis-admin group.</p>
<pre class="brush:text">
[gitosis]

[group gitosis-admin]
writable = gitosis-admin marketsim
members = jason@mymacbook.local

[repo marketsim]
gitweb = no
description = Market Simulation App
owner = Jason Miller
daemon = no
</pre>
<p>Alternatively I could create a new group with writable access to the 'marketsim' repository.</p>
<pre class="brush:text">
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = jason@mymacbook.local

[group marketsim-team]
members = jason@mymacbook.local
writable = marketsim

[repo marketsim]
gitweb = no
description = Market Simulation App
owner = Jason Miller
daemon = no
</pre>
<p>I could add 'newteammember.pub' in the 'keydir' folder, then add 'newteammember' after 'jason@mymacbook.local' separated by a space. This would make another team member part of that group which has write access to the repository.</p>
<p>After configuring a new repository, and giving my own local user write access to that repository, I've push the changes via a commit to the remote gitosis-admin repository.</p>
<p>NOTE: You may receive the warning "remote: WARNING:gitosis.gitweb.set_descriptions:Cannot find 'yourrepo' in '/home/git/repositories'". Ignore this and continue.</p>
<p>Now I'm going to initialize my new repository and push it to the remote server.</p>
<pre class="brush:shell">
$ cd marketsim
$ git init .
$ git add .
$ git commit -m "initial commit"
$ git remote add origin git@vps.web-app-host.com:marketsim.git
$ git push origin master
stdin: is not a tty
Initialized empty Git repository in /home/git/repositories/marketsim.git/
Counting objects: 3, done.
Writing objects: 100% (3/3), 209 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@vps.web-app-host.com:marketsim.git
 * [new branch]      master -> master
</pre>
<h2>Deploying to Server</h2>
<p>I've created an account with the username 'marketsi' to host the deployed application (cPanel only allows up to 8 characters for the username). Then I've logged into that account and added my public key via the SSH/Shell Access > Manage SSH Keys section of the cPanel account. </p>
<p>For property deployment you'll need to install the 'Bundler' gem so that the deployment script can install the gems needed for your application. You'll need to install this as 'root' so that the 'bundle' script is available under /usr/bin/bundle.</p>
<pre class="brush:shell">
$ ssh root@vps.web-app-host.com
root@vps [~]# gem install bundler
Fetching: bundler-1.0.21.gem (100%)
Successfully installed bundler-1.0.21
1 gem installed
Installing ri documentation for bundler-1.0.21...
Installing RDoc documentation for bundler-1.0.21...
root@vps [~]# which bundle
/usr/bin/bundle
</pre>
<p>I've modified my deploy.rb file for my Rails application like so:</p>
<pre class="brush:rails">
require "bundler/capistrano"
load "deploy/assets"

#############################################################
# Settings

set :application, "marketsim"
default_run_options[:pty] = true  # Must be set for the password prompt from git to work
set :use_sudo, false

set :user, "marketsi"  # The server's user for deploys
set :deploy_to, "/home/#{user}/rails"
set :ssh_options, { :forward_agent => true }

set :domain, "marketsim.org"
server domain, :app, :web
role :db, domain, :primary => true

#############################################################
# Git

set :scm, :git
set :repository,  "git@vps.web-app-host.com:marketsim.git"
set :branch, "master"
set :deploy_via, :remote_cache

#############################################################
# Passenger

namespace :passenger do
  desc "Restart Application"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

after :deploy, "passenger:restart"
</pre>
<p>Now to run the script to setup the deployment directories on the remote server.</p>
<pre class="brush:shell">
cap deploy:setup
</pre>
<p>This created a folder under /home/marketsi/rails with the 'releases' and 'shared' folder. Now I'll actually deploy.</p>
<pre class="brush:shell">
cap deploy
</pre>
<p>The gems were installed with no issue by Bundler for me. Hopefully the same goes for you.</p>
<h2>Passenger</h2>
<p>The next step is to configure Apache to serve the Rails application for my domain name. Install the Passenger gem via SSH logged in as root:</p>
<pre class="brush:shell">
gem install passenger
</pre>
<p>Install Passenger using the Apache module installation command. All dependencies should be found and displayed in green.</p>
<pre class="brush:shell">
passenger-install-apache2-module
</pre>
<p>At the end of the installation script it provides the Apache configuration settings which you place in httpd.conf. Since we're using cPanel, which over-writes the Apache configuration when the EasyApache system is used to rebuild Apache, PHP, and other modules, place this configuration in /usr/local/apache/conf/includes/pre_main_global.conf.</p>
<pre class="brush:text">
# /usr/local/apache/conf/includes/pre_main_global.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11
PassengerRuby /usr/bin/ruby
</pre>
<p>Next make a backup of the httpd.conf, run the configuration distiller script, rebuild, and then restart Apache.</p>
<pre class="brush:shell">
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak-modrails
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
</pre>
<p>The cPanel system makes the Apache Document Root for each account map to /home/username/public_html. Because of this you will need to remove the 'public_html' directory, and then create a symlink from that directory to the 'public' directory for your applications current release:</p>
<pre class="brush:shell">
rm -rf /home/marketsi/public_html/
ln -s /home/marketsi/rails/current/public /home/marketsi/public_html
chown marketsi:nobody public_html/
chmod 750 public_html/
</pre>
<p>Next add a .htaccess file in your application under the 'public' folder, and make sure it contains 'RailsBaseURI /', as well as a directive with the PassengerAppRoot.</p>
<pre class="brush:rails">
RailsBaseURI /
PassengerAppRoot /home/marketsi/rails/current
</pre>
<h2>MySQL Database</h2>
<p>If your application returns an error page 'We're sorry, but something went wrong.', check the production.log file on the server. In my case, the application was running, but it couldn't connect to the database with the existing database.yml settings for production.</p>
<p>As cPanel controls the MySQL databases and usernames, you'll have to create a database manually via the cPanel, create the user and assign all privileges to it for the database, and then configure your database.yml appropriately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/rails-3-on-whm-cpanel-vps-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configuring Rails 3.1.3 under Sub-URI</title>
		<link>http://www.redconfetti.com/2012/01/configuring-rails-3-1-3-under-sub-uri/</link>
		<comments>http://www.redconfetti.com/2012/01/configuring-rails-3-1-3-under-sub-uri/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 06:02:40 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[rails3.1]]></category>
		<category><![CDATA[relative_url_root]]></category>
		<category><![CDATA[sub-uri]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=969</guid>
		<description><![CDATA[In setting up a new Rails app recently I was told that it needed to be served under the sub-URI of &#8216;/info&#8217;. I hadn&#8217;t done this before with a Rails app, and I expected that it could be tricky. I checked online to see how this is done and found references to the &#8216;relative_url_root&#8217; setting,...]]></description>
			<content:encoded><![CDATA[<p>In setting up a new Rails app recently I was told that it needed to be served under the sub-URI of &#8216;/info&#8217;. I hadn&#8217;t done this before with a Rails app, and I expected that it could be tricky.</p>
<p>I checked online to see how this is done and found references to the &#8216;relative_url_root&#8217; setting, but then shortly found that this has been deprecated.</p>
<p>I&#8217;m using Phusion Passenger with Apache 2, so I inserted the following configuration into my VirtualHost entry for the site.</p>
<pre class="brush:text">
Alias /info /home/myapp/current/public
&lt;Location /info&gt;
  PassengerAppRoot /home/myapp/current
  RailsEnv production
&lt;/Location&gt;
</pre>
<p>The Rails application was expecting requests from the root of the site still. I found a StackOverflow article where someone suggested configuring all the routes under the &#8220;/info&#8221; scope like so:</p>
<pre class="brush:rails">
# config/routes.rb
scope "/info" do
  root :to =&gt; "welcome#index"
  resources :posts
end
</pre>
<p>This worked fine in development mode. I just made sure to pull up the pages using http://localhost:3000/info/</p>
<p>I had tested this in production before building out the application further, and it seemed to work fine. Later on when I deployed after many updates, I found that the application was referencing precompiled assets using &#8216;/assets/&#8217; and not &#8216;/info/assets/&#8217;. Further investigation pointed out that I needed to configure assets with a prefix like so:</p>
<pre class="brush:rails">
# config/application.rb
config.assets.prefix = "/info/assets"
</pre>
<p>This seemed like it would help, but this caused assets to be precompiled under &#8216;public/info/assets&#8217;.</p>
<p>I had previously Googled for &#8216;rails 3.1 subdirectory path&#8217;, not registering that the more appropriate keyword is &#8216;sub URI&#8217; for what I&#8217;m trying to accomplish.</p>
<p>It turns out that the best way to do this with Passenger is to mount the application to the sub-URI using the proper Apache configuration, and leave it up to the Rack interface to handle serving the requests to the Rails application, without using any Rails application configuration for the sub-URI.</p>
<p>I removed the scoped routes, and the assets prefix, returning my application to it&#8217;s default configuration. I then created a symbolic link for &#8216;info&#8217; in the websites DocumentRoot, pointing to the &#8216;public&#8217; folder of my application as per the <a href="http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rack_to_sub_uri" target="_blank">Passenger documentation</a>.</p>
<pre class="brush:shell">
ln -s /home/myapp/current/public /home/mysite/public_html/info
</pre>
<p>I added the appropriate configuration into my VirtualHost entry as advised by the Passenger documentation, but this only worked for the root of the website, not my admin area I had wanted to serve from /info/admin/. All I got was a 404 page from the main site.</p>
<p>I found that the following configuration worked perfectly, with the symbolic link still needing to be present.</p>
<pre class="brush:text">
Alias /info /home/myapp/current/public
&lt;Location /info&gt;
  PassengerAppRoot /home/myapp/current
  RackEnv production
  RackBaseURI /info
&lt;/Location&gt;
</pre>
<p>You might notice that I&#8217;m using &#8216;RackEnv production&#8217; instead of &#8216;RailsEnv production&#8217;. This is because I recall at some point previously that Rails 3.0 applications are Rack Applications, and thus you have to use &#8216;RackEnv&#8217; instead for Passenger to load the application in the proper environment mode.</p>
<hr />
<p>Update 01/04/12: I&#8217;m using the <a href="https://github.com/spohlenz/tinymce-rails" target="_blank">TinyMCE-Rails plugin</a> to provide a WYSIWYG editor for one of the resources in my application. It&#8217;s not loading in production however (surprise, surprise). I checked into the precompiled Javascript file being served from the live server, and I see it includes the following:</p>
<pre class="brush:javascript">
window.tinyMCEPreInit=window.tinyMCEPreInit||{base:"/assets/tinymce",query:"3.4.7",suffix:""}
</pre>
<p>The &#8216;base&#8217; value should be &#8216;/info/assets/tinymce&#8217;. I see that in the TinyMCE-Rails gem the coding for this is:</p>
<pre class="brush:rails">
window.tinyMCEPreInit = window.tinyMCEPreInit || {
  base:   '<%= Rails.application.config.assets.prefix %>/tinymce',
  query:  '<%= TinyMCE::VERSION %>',
  suffix: ''
};
</pre>
<p>All call to &#8216;asset_path(&#8216;rails.png&#8217;)&#8217; in production returns &#8216;/info/assets/rails-e4b51606cd77fda2615e7439907bfc92.png&#8217; so Rails is honoring the RackSubURI setting configured for Passenger. The following returns the same path.</p>
<p>The reason why this works is that the Rails asset helpers pull the relative_url_root value from the controller configuration, which must receive it from the Rack configuration. When deploying the app using Capistrano, such configuration is not present, and thus the correct path cannot be included in the precompiled assets.</p>
<p>The issue was reported via Git hub in issue #<a href="https://github.com/rails/rails/issues/3259" target="_blank">3259</a> and #<a href="https://github.com/rails/rails/issues/2435" target="_blank">2435</a>, and a fix will was implemented in Rails 3.2, with a possibly backport to Rails 3.1.4. </p>
<p>It appears that you&#8217;ll need to add a configuration to your application.rb or environments/production.rb, depending on how your development and production environments are setup.</p>
<pre class="brush:rails">
# config/environments/production.rb

# Use sub-uri in production
config.relative_url_root = '/info'
</pre>
<p>Or possibly configure your deployment script to include the environment variable when precompiling.</p>
<pre class="brush:shell">
RAILS_RELATIVE_URL_ROOT="/info" bundle exec rake assets:precompile
</pre>
<p>I wanted to test this, but I can&#8217;t seem to update to Rails 3.2, or install a new Rails app using edge Rails.</p>
<pre class="brush:shell">
rails new testapp --edge
.
.
.
Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    sass-rails (>= 0) ruby depends on
      actionpack (~> 3.1.0) ruby

    rails (>= 0) ruby depends on
      actionpack (4.0.0.beta)
</pre>
<p>I&#8217;m just going to configure my app under a subdomain instead of sub-uri for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/configuring-rails-3-1-3-under-sub-uri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Rake Tasks Not Loading</title>
		<link>http://www.redconfetti.com/2012/01/custom-rake-tasks-not-loading/</link>
		<comments>http://www.redconfetti.com/2012/01/custom-rake-tasks-not-loading/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 22:57:34 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=953</guid>
		<description><![CDATA[I recently went to create a new Rake task under /lib/tasks in a Rails application I&#8217;m working on. I didn&#8217;t understand why the rake tasks weren&#8217;t showing when I would run &#8216;rake -T&#8217; from the command line. When I&#8217;d try to run the task itself I would get a &#8216;Don&#8217;t know how to build task&#8217;...]]></description>
			<content:encoded><![CDATA[<p>I recently went to create a new Rake task under /lib/tasks in a Rails application I&#8217;m working on. I didn&#8217;t understand why the rake tasks weren&#8217;t showing when I would run &#8216;rake -T&#8217; from the command line.</p>
<p>When I&#8217;d try to run the task itself I would get a &#8216;Don&#8217;t know how to build task&#8217; error.</p>
<p>I just realized that I was naming my task file with the &#8216;.rb&#8217; extension, and not &#8216;.rake&#8217;. Doh!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/custom-rake-tasks-not-loading/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Troubleshooting ActiveResource Requests</title>
		<link>http://www.redconfetti.com/2012/01/troubleshooting-activeresource-requests/</link>
		<comments>http://www.redconfetti.com/2012/01/troubleshooting-activeresource-requests/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 22:46:52 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActiveResource]]></category>
		<category><![CDATA[HighRise]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[REST API]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=947</guid>
		<description><![CDATA[I&#8217;m currently working on an app which integrates with the HighRise API using the Highrise Ruby wrapper gem. The classes defined by the gem rely on ActiveResource, the Ruby library included with Rails for interfacing with RESTful resources like the HighRise API. Sometimes I&#8217;m not sure if the requests being made via the commands I&#8217;m...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on an app which integrates with the <a href="http://developer.37signals.com/highrise/people" target="_blank">HighRise API</a> using the <a href="https://github.com/tapajos/highrise" target="_blank">Highrise Ruby wrapper gem</a>. The classes defined by the gem rely on ActiveResource, the Ruby library included with Rails for interfacing with RESTful resources like the HighRise API.</p>
<p>Sometimes I&#8217;m not sure if the requests being made via the commands I&#8217;m using are making the right calls on the HighRise API.</p>
<p>I found this thread on StackOverflow: <a href="http://stackoverflow.com/questions/227907/how-do-i-view-the-http-response-to-an-activeresource-request" target="_blank">How do I view the HTTP response to an ActiveResource request?</a>. The solution I found helpful was this one on <a href="http://www.jroller.com/bokmann/entry/debugging_activerecord_web_services" target="_blank">overriding ActiveResource::Connection</a> so that it outputs the debug output. This worked for me even with Rails 3.1.</p>
<p>Just in case this article with the code disappears, here is the initializer code you can use to view the HTTP session data from the console. I&#8217;ve added an if statement to make sure the HTTP data is only outputted to the standard output in development mode, for <a href="http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-set_debug_output" target="_blank">security purposes</a>, as well as requires the environment variable &#8216;HTTPDEBUG&#8217;.</p>
<pre class="brush:rails"># /config/initializers/connection.rb
class ActiveResource::Connection
  # Creates new Net::HTTP instance for communication with
  # remote service and resources.
  def http
    http = Net::HTTP.new(@site.host, @site.port)
    http.use_ssl = @site.is_a?(URI::HTTPS)
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
    http.read_timeout = @timeout if @timeout
    #Here's the addition that allows you to see the output
    if Rails.env == 'development' &amp;&amp; ENV['HTTPDEBUG']
      http.set_debug_output $stderr
    end
    return http
  end
end</pre>
<p>You can open the Rails console using &#8216;HTTPDEBUG=true rails c&#8217; to activate the console with debugging output displayed in the console mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/troubleshooting-activeresource-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example Rake Task</title>
		<link>http://www.redconfetti.com/2012/01/example-rake-task/</link>
		<comments>http://www.redconfetti.com/2012/01/example-rake-task/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 22:26:28 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=943</guid>
		<description><![CDATA[Here is example rake task code which you can use and modify the next time you&#8217;re setting up new Rake tasks for a Rails app from scratch. The example includes the syntax for setting the default task, running multiple tasks in order, and a task which includes multiple arguments. This coding syntax works with Rails...]]></description>
			<content:encoded><![CDATA[<p>Here is example rake task code which you can use and modify the next time you&#8217;re setting up new Rake tasks for a Rails app from scratch. The example includes the syntax for setting the default task, running multiple tasks in order, and a task which includes multiple arguments. This coding syntax works with Rails 3.1.</p>
<pre class="brush:rails"># /lib/tasks/mytask.rake
namespace :mytask do

  task :default =&gt; 'mytask:full_run'

  desc "run all tasks in proper order"
  task :full_run =&gt; [:example_task_one, :example_task_two] do
    puts "All tasks ran and completed at #{Time.now}"
  end

  desc "example task without arguments"
  task :example_task_one =&gt; :environment do
    # task code goes here
    puts "Example Task One completed"
  end

  desc "example task with arguments"
  task :example_task_two, [:arg1, :arg2] =&gt; :environment do |t, args|
    # if no arguments, display docs
    if args.count == 0
      puts ''
      puts "rake mytask:example_task[arg1,arg2]"
      puts "arg1: description of first argument"
      puts "arg2: description of second argument"
      puts ''
      puts "example:"
      puts "rake mytask:example_task[123,'456']"
      puts ''
    else
      # task code goes here
      puts "Running task with arg1: #{args.arg1}, and arg2: #{args.arg2}"
      puts "Example Task Two completed"
    end
  end
end</pre>
<p>Special thanks to Jason Seifer for his <a href="http://jasonseifer.com/2010/04/06/rake-tutorial" target="_blank">Rake Tutorial</a> which made this possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2012/01/example-rake-task/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resolving issues with Namespaced Models in Rails 3.1.0</title>
		<link>http://www.redconfetti.com/2011/12/resolving-issues-with-namespaced-models-in-rails-3-1-0/</link>
		<comments>http://www.redconfetti.com/2011/12/resolving-issues-with-namespaced-models-in-rails-3-1-0/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 23:09:51 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[namespaced models]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3.1]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=929</guid>
		<description><![CDATA[I recently was tasked with upgrading an application from Rails 2.3.8 to Rails 3. I choose to upgrade it to Rails 3.1, because why upgrade once and then have to do it again later. After upgrading and testing many points of the system locally, I was ready to push the upgraded application to the production...]]></description>
			<content:encoded><![CDATA[<p>I recently was tasked with upgrading an application from Rails 2.3.8 to Rails 3. I choose to upgrade it to Rails 3.1, because why upgrade once and then have to do it again later.</p>
<p>After upgrading and testing many points of the system locally, I was ready to push the upgraded application to the production server. After pushing it out I started to notice that a certain rake task was failing to run via a cronjob I had setup. This rake task worked with certain non-ActiveRecord models, which I had setup with a hierarchy which utilized inheritance and namespacing.</p>
<p>Under Rails 2.3.8 I had a file, /app/models/rets_map/rets_map_base.rb. The error I was receiving from the rake task involved some sort of issue loading the class from this file.</p>
<p>As an experiment I renamed the file as &#8216;base.rb&#8217; so that it&#8217;s path was /app/models/rets_map/base.rb. I figured that Rails 3.1.0 expected this naming convention. I was right, kind of&#8230;</p>
<pre class="brush:shell">$ rails console
/Users/jason/Sites/rj4/rails/app/controllers/site_setup_controller.rb:120: warning: string literal in condition
Loading development environment (Rails 3.1.0)
irb(main):001:0&gt; RetsMap
=&gt; RetsMap
irb(main):002:0&gt; RetsMap::Base
=&gt; RetsMap::Base
irb(main):003:0&gt; reload!
Reloading...
=&gt; true
irb(main):004:0&gt; RetsMap
=&gt; RetsMap
irb(main):005:0&gt; RetsMap::Base
=&gt; RetsMap::Base
irb(main):006:0&gt; reload!
Reloading...
=&gt; true
irb(main):007:0&gt; RetsMap
=&gt; RetsMap
irb(main):008:0&gt; RetsMap::Base
LoadError: Expected /Users/jason/Sites/rj4/rails/app/models/rets_map/base.rb to define RetsMap::Base
	from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:490:in `load_missing_constant'
	from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:181:in `const_missing'
	from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `each'
	from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `const_missing'
	from (irb):8</pre>
<p>For some reason after I would tell the console to reload the models, I got an error that the file didn&#8217;t define RetsMap::Base&#8230;.but it did damnit!!</p>
<p>The error was regarding ActiveSupport, so I tried to reinstall the Rails gem and ActiveSupport gem, but this didn&#8217;t help.</p>
<p>The solution I had found was to upgrade to Rails 3.1.1. After doing this, the error no longer occurred, even after I had reloaded the models.</p>
<p>Ooh, also, I didn&#8217;t mention. Previously I was using the following command in /config/application.rb:</p>
<pre class="brush:rails">config.autoload_paths += Dir["#{config.root}/app/models/**/"]</pre>
<p>As part of my troubleshooting I figured that by default Rails will try to load models from subdirectories if they conform to the proper directory and file naming required for namespaced models. When you add models to the autoload paths configuration, I think it expects that those conventions don&#8217;t apply&#8230;or maybe this just causes problems. I commented this line out and simply added each subdirectory that contained non-namespaced models.</p>
<pre class="brush:rails">config.autoload_paths += %W(#{config.root}/app/models/email/)
config.autoload_paths += %W(#{config.root}/app/models/sub/)
config.autoload_paths += %W(#{config.root}/app/models/upload/)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2011/12/resolving-issues-with-namespaced-models-in-rails-3-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paperclip error with non-image file</title>
		<link>http://www.redconfetti.com/2011/12/paperclip-error-with-non-image-file/</link>
		<comments>http://www.redconfetti.com/2011/12/paperclip-error-with-non-image-file/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 20:43:25 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[identify]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[non-image]]></category>
		<category><![CDATA[paperclip]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=924</guid>
		<description><![CDATA[Recently I updated to Rails 3.1 from 2.3.8 for a project I&#8217;m working on. Paperclip version 2.4.5 was working perfectly well for me locally on my Mac OS X 10.7.2 laptop, with ImageMagick version 6.7.3-1. We had just launched the upgraded Rails 3.1 application to our production server, which went smoothly, but upon my checklist of...]]></description>
			<content:encoded><![CDATA[<p>Recently I updated to Rails 3.1 from 2.3.8 for a project I&#8217;m working on. Paperclip version 2.4.5 was working perfectly well for me locally on my Mac OS X 10.7.2 laptop, with ImageMagick version 6.7.3-1.</p>
<p>We had just launched the upgraded Rails 3.1 application to our production server, which went smoothly, but upon my checklist of pages to test (we don&#8217;t have test suite in use yet) I noticed that the file upload was failing. Further investigation showed that the object using paperclip was failing to save:</p>
<pre class="brush:shell">upload.errors.inspect: 

#["/tmp/stream20111205-28441-10oj2ck-0.csv is not recognized by the 'identify' command.", "/tmp/stream20111205-28441-10oj2ck-0.csv is not recognized by the 'identify' command."]}&gt;, @base=#&gt;</pre>
<p>Further investigation helped me identify this &#8216;identify&#8217; command as an executable provided by ImageMagick. I ran this command on the temporary file which was located in /tmp, and I got an error such as the one that follows on both my local machine and in production. The odd thing was that the file upload worked locally, but was failing remotely.</p>
<pre class="brush:shell">$ identify test-import20111205-1909-1xsbr19-0.csv 

identify: no decode delegate for this image format `test-import20111205-1909-1xsbr19-0.csv' @ error/constitute.c/ReadImage/532.</pre>
<p>This didn&#8217;t make sense. I was uploading a CSV file, not an image. I wasn&#8217;t even using the &#8216;:styles&#8217; hash value in my model with the &#8216;has_attached_file&#8217; expression. Why was it checking to see what type of image the file is?!?!</p>
<p>I tried to upgrade and reinstall ImageMagick on the production server, but this had no effect. This made me suspect that paperclip was the cause of the issue. I also created an initalizer for paperclip under /config/initalizers/paperclip.rb pointing out the image_magick_path, which I had seen resolve other issues with &#8216;identify&#8217; errors.</p>
<pre class="brush:rails">if Rails.env == 'production'
  Paperclip.options[:image_magick_path] = "/usr/bin/"
end</pre>
<p>This didn&#8217;t help at all.</p>
<p>I tried to reconfigure the application to use Paperclip version 2.4.4 and 2.4.3, but that didn&#8217;t resolve the issue.</p>
<p>Finally I updated my Gemfile to use the latest Github version of Paperclip. I deployed this update, tested, and finally the issue was resolved.</p>
<pre class="brush:rails">gem 'paperclip', "~&gt; 2.4.5", :git =&gt; 'git://github.com/thoughtbot/paperclip.git'</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2011/12/paperclip-error-with-non-image-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issues with RVM</title>
		<link>http://www.redconfetti.com/2011/11/issues-with-rvm/</link>
		<comments>http://www.redconfetti.com/2011/11/issues-with-rvm/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 00:11:04 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[os x lion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=912</guid>
		<description><![CDATA[I recently decided to check out BrowserCMS, to evaluate how it work and decide to use it&#8230;or RefineryCMS. I didn&#8217;t expect that BrowserCMS would require Ruby 1.9.2. I&#8217;ve been running with Ruby 1.8.6 or 1.8.7 for quite a while now without any issues. It looks like it was time that I install RVM: Ruby Version Manager....]]></description>
			<content:encoded><![CDATA[<p>I recently decided to check out <a title="BrowserCMS - BrowserCMS - Open Source, Ruby on Rails CMS" href="http://www.browsercms.org/" target="_blank">BrowserCMS</a>, to evaluate how it work and decide to use it&#8230;or <a title="Refinery CMS - a CMS that supports Rails 3" href="http://www.refinerycms.com/" target="_blank">RefineryCMS</a>. I didn&#8217;t expect that BrowserCMS would require Ruby 1.9.2. I&#8217;ve been running with Ruby 1.8.6 or 1.8.7 for quite a while now without any issues. It looks like it was time that I install <a title="RVM: Ruby Version Manager" href="https://rvm.beginrescueend.com/" target="_blank">RVM: Ruby Version Manager</a>.</p>
<p>I read through the documentation, followed the instructions to ensure that prerequisite software was installed. I specifically made sure that certain commands that it stated would be needed were all in my command line path under /opt/local, where the MacPorts all install. I try to maintain a command line environment that&#8217;s almost entirely dependent on MacPorts. Prior to ensuring this I ran into issues where software I&#8217;ve tried to install was using one utility or library provided natively by Mac OS X, while using some other utility or library I&#8217;ve installed separately, conflict due to differences and stop certain software from building properly upon install.</p>
<p>I also took note that since I&#8217;m using MacPorts, I should <a href="https://rvm.beginrescueend.com/integration/macports/" target="_blank">configure my $HOME/.rvmrc</a> file so that RVM uses my MacPort libraries when building gems.</p>
<h2>Installation of Ruby</h2>
<p>The installation of the RVM software itself went smoothly. I felt good knowing that I was about to learn how RVM works and it will become another tool that I gladly assign to my arsenal of software to be used in the future (and add to my resume).</p>
<p>Then I ran into an issue with something in &#8216;readline.c&#8217; when I attempted to install Ruby 1.8.7.</p>
<pre class="brush:rails">jason@imac ~$ rvm install 1.8.7 --with-openssl-dir=/opt/local

Installing Ruby from source to: /Users/jason/.rvm/rubies/ruby-1.8.7-p352, this may take a while depending on your cpu(s)...

ruby-1.8.7-p352 - #fetching
ruby-1.8.7-p352 - #extracting ruby-1.8.7-p352 to /Users/jason/.rvm/src/ruby-1.8.7-p352
ruby-1.8.7-p352 - #extracted to /Users/jason/.rvm/src/ruby-1.8.7-p352
Applying patch 'stdout-rouge-fix' (located at /Users/jason/.rvm/patches/ruby/1.8.7/stdout-rouge-fix.patch)
ruby-1.8.7-p352 - #configuring
ruby-1.8.7-p352 - #compiling
ERROR: Error running 'make ', please read /Users/jason/.rvm/log/ruby-1.8.7-p352/make.log
ERROR: There has been an error while running make. Halting the installation.

jason@imac ~$ tail -10 /Users/jason/.rvm/log/ruby-1.8.7-p352/make.log
.
.
.
compiling readline
/usr/bin/gcc-4.2 -I. -I../.. -I../../. -I../.././ext/readline -DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -DHAVE_RL_FILENAME_COMPLETION_FUNCTION -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_DEPREP_TERM_FUNCTION -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_BASIC_WORD_BREAK_CHARACTERS -DHAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS -DHAVE_RL_BASIC_QUOTE_CHARACTERS -DHAVE_RL_COMPLETER_QUOTE_CHARACTERS -DHAVE_RL_FILENAME_QUOTE_CHARACTERS -DHAVE_RL_ATTEMPTED_COMPLETION_OVER -DHAVE_RL_LIBRARY_VERSION -DHAVE_RL_EVENT_HOOK -DHAVE_RL_CLEANUP_AFTER_SIGNAL -DHAVE_REPLACE_HISTORY_ENTRY -DHAVE_REMOVE_HISTORY -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/opt/local/include -fno-common -arch x86_64 -g -Os -pipe -no-cpp-precomp  -fno-common -pipe -fno-common   -c readline.c
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)
make[1]: *** [readline.o] Error 1
make: *** [all] Error 1</pre>
<p>I tried to install &#8216;readline&#8217; using MacPorts because I read online that this was a common issue with Mac OS X users under Snow Leopard. This didn&#8217;t help, and in fact I got an error after trying to install readline from source as recommended in the forum post I found regarding the subject.</p>
<p>After further search, I realized that the RVM documentation (which is pretty good I must say) has <a title="RVM install ruby readline" href="https://rvm.beginrescueend.com/packages/readline/" target="_blank">a page devoted to this issue</a>.</p>
<h2>Issue Installing Custom Gems</h2>
<p>Later I had installed Ruby 1.9.2 as well, because I needed it for BrowserCMS. I was trying to install gems for Ruby, but each time it would give me the &#8216;Invalid gemspec &#8230; invalid date format in specification&#8217; error that I recall from a time when I was using a newer version of RubyGems than the gems I had installed were made for, like:</p>
<pre class="brush:rails">Invalid gemspec in [/opt/local/lib/ruby/gems/1.8/specifications/paperclip-2.4.3.gemspec]: invalid date format in specification: "2011-10-05 00:00:00.000000000Z"</pre>
<p>I made sure I was running under Ruby 1.9.2, and that the version of RubyGems would be the one associated with Ruby version 1.9.2, and then upgraded it to version</p>
<pre class="brush:rails">imac:Sites jason$ rvm 1.9.2
imac:Sites jason$ rvm gemdir
/Users/jason/.rvm/gems/ruby-1.9.2-p290
imac:Sites jason$ rvm rubygems current
Removing old Rubygems files...
Installing rubygems-1.8.10 for ruby-1.9.2-p290 ...
Installation of rubygems completed successfully.</pre>
<p>I tried to check or change which version of gem I was using, and it would tell me it&#8217;s using one installed under RVM, but still it would give errors as if it was using an older version of RubyGems.</p>
<pre class="brush:rails">imac:Sites jason$ which gem
/Users/jason/.rvm/rubies/ruby-1.9.2-p290/bin/gem

imac:Sites jason$ sudo gem install browsercms

Invalid gemspec in [/opt/local/lib/ruby/gems/1.8/specifications/capistrano-2.9.0.gemspec]: invalid date format in specification: "2011-09-24 00:00:00.000000000Z"</pre>
<p>I then found out that I had a .gemrc file setup that was loading in my command line environment, and thus interfering with the dependency loading which RVM provides.</p>
<pre class="brush:rails">imac:Sites jason$ cd ~
imac:~ jason$ cat .gemrc
gemhome: /opt/local/lib/ruby/gems/1.8
gempath:
 - /opt/local/lib/ruby/gems/1.8
 - /Users/jason/gems
imac:~ jason$</pre>
<p>I simply renamed this file as .gemrc.bak and this resolved the issue so that gems I install under Ruby v1.9.2 will use the RubyGem version associated with the Ruby 1.9.2 installation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2011/11/issues-with-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect_to not working</title>
		<link>http://www.redconfetti.com/2011/09/redirect_to-not-working/</link>
		<comments>http://www.redconfetti.com/2011/09/redirect_to-not-working/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 20:37:59 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[http post]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=896</guid>
		<description><![CDATA[I was just working on a Ruby on Rails controller method that receives information from the previous form via HTTP POST. I coded it so that if certain form variables weren&#8217;t present it would set a flash message and redirect to the form page. I tried and tried and still the redirect wasn&#8217;t working. I...]]></description>
			<content:encoded><![CDATA[<p>I was just working on a Ruby on Rails controller method that receives information from the previous form via HTTP POST. I coded it so that if certain form variables weren&#8217;t present it would set a flash message and redirect to the form page. I tried and tried and still the redirect wasn&#8217;t working. I reset my web server, and even restarted my computer, but stil this didn&#8217;t resolve the issue.</p>
<p>I then realized that perhaps redirects aren&#8217;t possible with HTTP POST&#8217;s, only GET requests. I ended up just creating a generic view for displaying errors, and will render that view and then &#8216;return FALSE&#8217; inside of the if statement when an error is detected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2011/09/redirect_to-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Use of Will_Paginate</title>
		<link>http://www.redconfetti.com/2011/09/advanced-use-of-will_paginate/</link>
		<comments>http://www.redconfetti.com/2011/09/advanced-use-of-will_paginate/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 22:08:56 +0000</pubDate>
		<dc:creator>redconfetti</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[will_paginate]]></category>

		<guid isPermaLink="false">http://www.redconfetti.com/?p=859</guid>
		<description><![CDATA[I&#8217;m building an index of contacts, displayed with paginated links provided by will_paginate. The wiki for this plugin advises you on how to do setup your controller method, and what to put in the view to obtain a simple set of links, such as: # /app/controllers/contact_controller.rb def index @contacts = Contact.paginate :page =&#62; params[:page], :per_page...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m building an index of contacts, displayed with paginated links provided by <a href="https://github.com/mislav/will_paginate/wiki" target="_blank">will_paginate</a>.</p>
<p>The wiki for this plugin advises you on how to do setup your controller method, and what to put in the view to obtain a simple set of links, such as:</p>
<pre class="brush:rails"># /app/controllers/contact_controller.rb
def index
  @contacts = Contact.paginate :page =&gt; params[:page], :per_page =&gt; 10, :order =&gt; 'created_at DESC'
end

# /app/views/contact/index.html.erb
&lt;%= will_paginate @contacts %&gt;</pre>
<p>What I&#8217;m not finding however are more advanced methods of using the will_paginate plugin. Here are a few things I&#8217;ve found.</p>
<h3>Links at top and bottom of paginated section</h3>
<p>You can add the paginated links to the top and bottom of your paginated section using this syntax:</p>
<pre class="brush:rails">&lt;% paginated_section @contacts do %&gt;
	&lt;table id="contacts"&gt;
		&lt;%= render(:partial =&gt; "contact_row", :collection =&gt; @contacts) %&gt;
	&lt;/table&gt;
&lt;% end %&gt;</pre>
<h3>Display Page Entries Info</h3>
<p>You can display text on your page such as &#8216;Displaying contacts <strong>11 - 12</strong> of <strong>12</strong> in total&#8217; by using the following view helper.</p>
<pre class="brush:rails">&lt;%= page_entries_info @contacts %&gt;</pre>
<h3>Current and Total Page Number</h3>
<p>If you want to display the total number of pages in your own way, you can do this by using the &#8216;total_pages&#8217; method of the paginated collection.</p>
<pre class="brush:rails">&lt;p&gt;You are viewing page &lt;%= @contacts.current_page %&gt;
of &lt;%= @contacts.total_pages %&gt;&lt;/p&gt;</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redconfetti.com/2011/09/advanced-use-of-will_paginate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

