<?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>Sentia &#124; Sydney IT Consultancy, Software Development, Ruby on Rails, Web Application Development, Rails Development, Test Driven Development, Microsoft.Net, Asp.Net , Agile, Continuous Integration Training, iPhone development &#187; ruby</title>
	<atom:link href="http://www.sentia.com.au/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sentia.com.au</link>
	<description>Sentia company website and blog about all things development, Ruby on Rails, Microsoft .Net, ASP.Net, C#.Net, Agile web development, Test Driven Development</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:16:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Adding your own login method to Authlogic</title>
		<link>http://www.sentia.com.au/2009/06/adding-your-own-login-method-to-authlogic/</link>
		<comments>http://www.sentia.com.au/2009/06/adding-your-own-login-method-to-authlogic/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 02:51:39 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=294</guid>
		<description><![CDATA[So on a new project we are working on we &#8230; <a href="http://www.sentia.com.au/2009/06/adding-your-own-login-method-to-authlogic/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So on a new project we are working on we have a need for a user to be able to login via either their &#8220;Login&#8221; or &#8220;Mobile&#8221; number. Now we are using the <a href="http://github.com/binarylogic/authlogic/tree/master">Authlogic</a> gem which is a great gem and comes with all default methods for login etc and allows you to customise this very easily.</p>
<p>So firstly you need to add the following to your UserSession model. What this does is overwrite the default login method with the one we are defining below called &#8220;find_by_username_or_mobile&#8221;.</p>
<pre class="brush: ruby; title: ; notranslate">
class UserSession &lt; Authlogic::Session::Base
  find_by_login_method :find_by_username_or_mobile
end
</pre>
<p>Then in your user model its as simply as creating the class method for login. Now of course the password is still apart of the login process but we only wanted to allow users to either login via their login or mobile so no need to change the password methods.</p>
<pre class="brush: ruby; title: ; notranslate">
class User &lt; ActiveRecord::Base
  def self.find_by_username_or_mobile(login)
    find_by_login(login) || find_by_mobile(login)
  end
end
</pre>
<p>So give it a try and let us know how you go hope this helps</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/06/adding-your-own-login-method-to-authlogic/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Formatting Paypal dates</title>
		<link>http://www.sentia.com.au/2009/06/formatting-paypal-dates/</link>
		<comments>http://www.sentia.com.au/2009/06/formatting-paypal-dates/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 04:09:23 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=280</guid>
		<description><![CDATA[We have been doing a some work on PayPal integration &#8230; <a href="http://www.sentia.com.au/2009/06/formatting-paypal-dates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have been doing a some work on PayPal integration for one of our clients for their soon to be released application and l needed to reformat the date PayPal was sending me. Now l know that <a href="http://www.activemerchant.org/">Active Merchant</a> could help with this but it didn&#8217;t fit our application.</p>
<p>So any ways PayPal sends you a date like so <strong>&#8220;03:25:17 Apr 26, 2007 PDT&#8221;</strong> and l need it in a clean format so here is what l came up with, its a first run and l am sure l will change it when the time comes to refactor but for now it works.</p>
<pre class="brush: ruby; title: ; notranslate">
  def self.date_from_paypal(datetime_string)
    datetime_string =~ /(d+):(d+):(d+) (.+) (d+), (d+)/
    parseable_string = &quot;#$6-#$4-#$5T#$1:#$2:#$3&quot;
    DateTime.parse(parseable_string)
  end

  %w(payment_date).each do |attrib|
    module_eval %{
      def #{attrib}=(datetime_string)
        write_paypal_date :#{attrib}, datetime_string
      end
    }
  end

  private

  def write_paypal_date(attribute, datetime_string)
    write_attribute attribute, PaypalTransaction.date_from_paypal(datetime_string)
  end
</pre>
<p>So what it does is when you go to set the &#8220;payment_date&#8221; field it runs the &#8220;write_paypal_date&#8221; method which formats the date for you a little cleaner. You can add other dates to this very simply by just adding them to the string array in the method above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/06/formatting-paypal-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application templates in Ruby on Rails</title>
		<link>http://www.sentia.com.au/2009/05/application-templates-in-ruby-on-rails/</link>
		<comments>http://www.sentia.com.au/2009/05/application-templates-in-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 08 May 2009 05:59:24 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[application templates]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=218</guid>
		<description><![CDATA[Here is the latest application template we have put together. &#8230; <a href="http://www.sentia.com.au/2009/05/application-templates-in-ruby-on-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is the latest application template we have put together. It removes all the usual items and adds the base gems that we use for all our applications. It also creates the files needed for deployment and runs &#8220;Capify&#8221; on the project, plus a few other things such as sass etc.</p>
<pre class="brush: ruby; title: ; notranslate">
# Remove unnecessary Rails files
run 'rm README'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/images/rails.png'
run 'rm -f public/javascripts/*'

# Download JQuery
run &quot;curl -s -L http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js &gt; public/javascripts/jquery.js&quot;
run &quot;curl -s -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js &gt; public/javascripts/jquery.form.js&quot;

#Configure required gems
gem &quot;haml&quot;, :version =&gt; &quot;2.0.4&quot;
gem 'thoughtbot-shoulda', :lib =&gt; 'shoulda', :source =&gt; 'http://gems.github.com'
gem &quot;thoughtbot-factory_girl&quot;, :lib =&gt; &quot;factory_girl&quot;, :source =&gt; &quot;http://gems.github.com&quot;

#Create Sass directory
run 'mkdir public/stylesheets/sass'

#Capify and create production environment.rb
run 'mkdir config/deploy'
run 'touch config/deploy/production.rb'

#Add UAT environment and settings
file 'config/environments/uat.rb', &lt;&lt;-CODE
# Settings specified here will take precedence over those in config/environment.rb

# Code is not reloaded between requests. Server needs to be restarted.
config.cache_classes = true

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true
config.action_view.cache_template_loading            = true

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
CODE

#Create gitignore file and setup base ignores
run &quot;touch tmp/.gitignore log/.gitignore vendor/.gitignore&quot;
file '.gitignore', &lt;&lt;-FILE
.DS_Store
log/*.log
tmp/**/*
db/*.sqlite3
public/stylesheets/*.css
FILE

# Set up git repository
git :init
git :add =&gt; '.'
git :commit =&gt; &quot;-a -m 'Initial commit'&quot;

# Success!
puts &quot;SUCCESS!&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/05/application-templates-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Javascript Code for RJS Instead of IDs</title>
		<link>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/</link>
		<comments>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 11:47:24 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rjs]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=175</guid>
		<description><![CDATA[UPDATE: JavascriptGenerator has a method name literal that will do &#8230; <a href="http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p> UPDATE: JavascriptGenerator has a method name literal that will do the exact same thing, so the code below should do the trick:</p>
<pre class="brush: ruby; title: ; notranslate">
 page.insert_html :bottom, page.literal(&quot;$$('p.welcome b').first()&quot;), &quot;Some item&quot;
</pre>
<p>Bill Burhcam over at <a href="http://www.meme-rocket.com/2007/04/10/fight-id-proliferation-and-update-any-element-you-want/">Meme Rocket</a> made a post that *almost* solved a problem for me the other day. We&#8217;re currently doing some work that ends up creating html. Pretty standard stuff, but for a few reasons that aren&#8217;t really worth going into we can&#8217;t easily rely on our element ids being unique. The prototype functions &#8216;up&#8217; and &#8216;down&#8217; are perfect for this situation though.</p>
<p>So our problem basically boils down to this &#8211; RJS converts this code:</p>
<pre class="brush: ruby; title: ; notranslate">
page.insert_html :bottom, &quot;$$('p.welcome b').first()&quot;, &quot;Some item&quot;
</pre>
<p>into this javascript:</p>
<pre class="brush: jscript; title: ; notranslate">
 new Insertion.Bottom(&quot;$$('p.welcome b').first()&quot;, &quot;Some item&quot;
</pre>
<p>Because the $$(&#8216;p&#8230;&#8217;) is in quotes, Insertion.Bottom just looks for an element with that id. Which isn&#8217;t what we really wanted.</p>
<p>After digging around in the ActionView source for a while I found JavascriptGenerator::GeneratorMethods and its javascript_object_for method. It turns out that if you pass in a ActiveSupport::JSON::Variable then insert_html will behave how we want. So for the example above, the code below will work as expected.</p>
<pre class="brush: ruby; title: ; notranslate">
 js_literal = &quot;$$('p.welcome b').first()&quot; js_literal = ActiveSupport::JSON::Variable.new(js_literal) page.insert_html :bottom, js_literal, &quot;Some item&quot;
</pre>
<p>will output:</p>
<pre class="brush: ruby; title: ; notranslate">
 new Insertion.Bottom($$('p.welcome b').first(), &quot;Some item&quot;
</pre>
<p>Thank you open source. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

