<?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/"
	>

<channel>
	<title>RAILS trip</title>
	<atom:link href="http://railstrip.ourgreatjourney.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://railstrip.ourgreatjourney.com</link>
	<description>My Ruby trip on Rails</description>
	<pubDate>Thu, 12 Nov 2009 21:36:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to paginate, sort and search a table with Ajax and Rails (JQuery Style with will_paginate plugin)</title>
		<link>http://railstrip.ourgreatjourney.com/how-to-paginate-sort-and-search-a-table-with-ajax-and-rails-jquery-style/</link>
		<comments>http://railstrip.ourgreatjourney.com/how-to-paginate-sort-and-search-a-table-with-ajax-and-rails-jquery-style/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 18:23:21 +0000</pubDate>
		<dc:creator>Chris Sund</dc:creator>
		
		<category><![CDATA[Rails Stuff]]></category>

		<guid isPermaLink="false">http://railstrip.ourgreatjourney.com/?p=66</guid>
		<description><![CDATA[Hey Everyone,
Today I decided to try and paginate, sort and search my account index using &#8220;Jrails&#8221; and  &#8220;will_paginate&#8221; plugin. I took my ques from an article posted @ http://dev.nozav.org/rails_ajax_table.html#sec8. I changed it up a bit and switched out the prototype library with JQuery using the &#8220;Jrails&#8221; plugin to drop in JQuery. I also opted [...]]]></description>
			<content:encoded><![CDATA[<p>Hey Everyone,</p>
<p>Today I decided to try and paginate, sort and search my account index using &#8220;Jrails&#8221; and  &#8220;will_paginate&#8221; plugin. I took my ques from an article posted @ http://dev.nozav.org/rails_ajax_table.html#sec8. I changed it up a bit and switched out the prototype library with JQuery using the &#8220;Jrails&#8221; plugin to drop in JQuery. I also opted to use the &#8220;will_paginate&#8221; plugin rather than the classic_pagination plugin.</p>
<h4>Screenshot1</h4>
<p><img src="/images/search_example.png"></p>
<h4>Screenshot2</h4>
<p><img src="/images/search_example2.png"><BR><br />
<strong>Resources:</strong></p>
<p><strong>script/plugin install git://github.com/futuresinc/jrails.git</strong><br />
<strong>script/plugin install git://github.com/mislav/will_paginate.git</strong><br />
<a href="http://mentalized.net/activity-indicators/">Graphics for spinner.gif</a></p>
<p> I will try and keep this short and sweet, if you have questions please post a comment. I will do my best to answer them.</p>
<p><strong>APPLICATION LAYOUT</strong></p>
<p><strong>Note:</strong> <em>I had a problem when trying to use the observe_field due to the fact I have other js libraries loading. I would get an error &#8220;delayedObserver is not a function&#8221;. You need to make sure your other libraries don&#8217;t interfere with jrails loading. If you&#8217;re having this problem, remove everything else until you get it to work, and add back each js library one at a time. Just my experience. </em></p>
<p><script src='http://pastie.org/693949.js'></script></p>
<p><strong>VIEW (list.html.erb)</strong></p>
<p><script src='http://pastie.org/694058.js'></script></p>
<p><strong>PARTIAL (_items_list.html.erb)</strong></p>
<p><script src='http://pastie.org/693976.js'></script></p>
<p><strong>CONTROLLER METHOD</strong></p>
<p><script src='http://pastie.org/693981.js'></script></p>
<p><strong>HELPER METHODS</strong></p>
<p><script src='http://pastie.org/693983.js'></script></p>
<p><strong>DIFFERENCES</strong></p>
<p>The major difference between the original article and this one is the fact that I had to replace the prototype syntax for jquery syntax in the controllers, helpers, and views. This mainly revolved around changing the following</p>
<p><strong>Prototype:</strong> Element.show(&#8217;spinner&#8217;)<BR><br />
<strong>Jquery version:</strong> $(&#8217;#spinner&#8217;).show()</p>
<p>This applies to the hide element as well. I also used the will_paginate plugin </p>
<p><strong>NEXT STEP FOR ME&#8230;</strong></p>
<p>My next step I hope to accomplish today is add a drop down list so the user can choose which field they want to filter by. Once I add this, I will post my code. If I don&#8217;t add it, or come up with something different, I will post that. </p>
<p>Thanks!</p>
<p>Chris</p>
<p>Feel free to post comments. If you have a better way to do this, or feel I did something wrong I would love to hear.<br />
<HR><br />
<H3>ADDING SELECT TO CHOOSE SEARCH CRITERIA</H3></p>
<p> This morning I tackled adding a select box so the user can choose which field they would like to search on. This wasn&#8217;t too difficult, but it caused me to use the &#8220;observe_form&#8221; helper rather than the &#8220;observe_field&#8221;. Here&#8217;s my code&#8230;</p>
<p><strong>CONTROLLER METHOD</strong></p>
<p><script src='http://pastie.org/695596.js'></script></p>
<p><strong>VIEW</strong></p>
<p><script src='http://pastie.org/695597.js'></script></p>
<p><strong>PARTIAL</strong><br />
<P>Note: This didn&#8217;t change</p>
<p><script src='http://pastie.org/695601.js'></script></p>
<p> As always I&#8217;m open to comments or suggestions. I populated my database with 200K records and the search completed on each field in less than 3 seconds. I was really surprised and happy with the results. Let me know what you think.</p>
<p>Chris</p>
]]></content:encoded>
			<wfw:commentRss>http://railstrip.ourgreatjourney.com/how-to-paginate-sort-and-search-a-table-with-ajax-and-rails-jquery-style/feed/</wfw:commentRss>
		</item>
		<item>
		<title>observe_field (watch check_box_tag so select_tag can be disabled on click)</title>
		<link>http://railstrip.ourgreatjourney.com/observe_field-watch-check_box_tag-so-select_tag-can-be-disabled-on-click/</link>
		<comments>http://railstrip.ourgreatjourney.com/observe_field-watch-check_box_tag-so-select_tag-can-be-disabled-on-click/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 17:44:23 +0000</pubDate>
		<dc:creator>Chris Sund</dc:creator>
		
		<category><![CDATA[Rails Stuff]]></category>

		<guid isPermaLink="false">http://railstrip.ourgreatjourney.com/?p=50</guid>
		<description><![CDATA[Hey Everyone,
This past week I had a scenerio where I needed to &#8220;disable&#8221; a rails select_tag if a check box on my form was clicked. To make this worse, the select boxes were dynamically created through an array so the id&#8217;s were created dynamically too. That shouldn&#8217;t make any difference in this little tutorial however.
In [...]]]></description>
			<content:encoded><![CDATA[<p>Hey Everyone,</p>
<p>This past week I had a scenerio where I needed to &#8220;disable&#8221; a rails select_tag if a check box on my form was clicked. To make this worse, the select boxes were dynamically created through an array so the id&#8217;s were created dynamically too. That shouldn&#8217;t make any difference in this little tutorial however.</p>
<p>In the title of my post is mention <strong>&#8220;observe_field&#8221;</strong>. This is how I preferred to implement this solution due to the fact I&#8217;m not a Javascript programmer, but this isn&#8217;t the path I took.  I ended up using straight JS to complete this, and it was &#8220;REALLY&#8221; easy. I should mention that I&#8217;m using JRAILS to replace prototype with JQuery. I tested this on both however and it worked fine. Here&#8217;s what I did&#8230;</p>
<p>In my view I had two items (The checkbox and the selectbox)</p>
<div id="code_block">
<p>&lt;%= check_box_tag &#8216;lock_settings_option&#8217;, &#8216;1&#8242;, @checked, :id =&gt; &#8216;lock_settings&#8217;, :onchange =&gt; &#8220;Change()&#8221;%&gt;<label for="lock_settings">Lock Settings</label></p>
<p>&lt;%= select_tag( &#8220;fields[#{c}]&#8220;, options_for_select(@fields, @default.to_i), :id =&gt; &#8220;field#{c}&#8221;, :disabled =&gt; @moption, :include_blank =&gt; &#8216;true&#8217;,  :class =&gt; &#8216;field_options&#8217;) %&gt;
</p></div>
<p>To get this to work I added the following Javascript to the bottom of my view (keep in mind I had these two items in a form, that&#8217;s the reason you see &#8220;mapped_fields_form&#8221; in the example. It&#8217;s also important to understand that my id&#8217;s were assigned dynamically. The area on my select_tag that says &#8220;:id => &#8220;field#{c}&#8221; is where it assigns &#8220;field1, field2, field3 etc&#8221;. </p>
<div id="code_block">
<strong>NOTE: I had to replace the < with [ in this blog post so it would display properly. </strong><br />
[script language="javascript"]<br />
function Change()<br />
{<br />
if (document.map_fields_form.lock_settings.checked == true)<br />
  {<br />
       document.map_fields_form.field1.disabled = true;<br />
       document.map_fields_form.field2.disabled = true;<br />
       document.map_fields_form.field3.disabled = true;<br />
       document.map_fields_form.field4.disabled = true;<br />
       document.map_fields_form.field5.disabled = true;<br />
       document.map_fields_form.field6.disabled = true;<br />
  }<br />
else<br />
  {<br />
      document.map_fields_form.field1.disabled = false;<br />
      document.map_fields_form.field2.disabled = false;<br />
      document.map_fields_form.field3.disabled = false;<br />
      document.map_fields_form.field4.disabled = false;<br />
      document.map_fields_form.field5.disabled = false;<br />
      document.map_fields_form.field6.disabled = false;<br />
  }<br />
}<br />
[/script]
</div>
<p>In my controller I placed the following so the checkbox and the select box would load with the proper choice. In my case if a certain field was empty then I wanted the fields to be &#8220;enabled&#8221;, but if it wasn&#8217;t  then I wanted them to be disabled. </p>
<div id="code_block">
<p>get_preferences = Preference.find(:first)</p>
<p>      if get_preferences.handheld_mapping.empty?</p>
<p>         @moption = false<br />
        @checked = false<br />
      else<br />
        @moption = true<br />
        @checked = true</p>
<p>      end</p>
</div>
<p>I hope this helps someone down the road. I had hard time finding a solution that would work. If someone knows how this could be implemented using observe_field I&#8217;m all ears. In addition, if you have a comment, please post it.</p>
<p>Thanks!</p>
<p>Chris</p>
]]></content:encoded>
			<wfw:commentRss>http://railstrip.ourgreatjourney.com/observe_field-watch-check_box_tag-so-select_tag-can-be-disabled-on-click/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sphinx + Mac + Postgresql = unknown type &#8216;pgsql&#8217;; skipping</title>
		<link>http://railstrip.ourgreatjourney.com/sphinx-mac-postgresql-unknown-type-pgsql-skipping/</link>
		<comments>http://railstrip.ourgreatjourney.com/sphinx-mac-postgresql-unknown-type-pgsql-skipping/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 19:23:22 +0000</pubDate>
		<dc:creator>Chris Sund</dc:creator>
		
		<category><![CDATA[Rails Stuff]]></category>

		<guid isPermaLink="false">http://railstrip.ourgreatjourney.com/?p=34</guid>
		<description><![CDATA[Hey Everyone,
I&#8217;m posting this blog article due to the fact I had this problem and never found a solution online. With the help of Pat Allen and the ThinkingSphinx google group I was able to find a solution.  My problem had nothing to do with not compiling using (&#8211;with-pgsql) it was far more obscure. [...]]]></description>
			<content:encoded><![CDATA[<p>Hey Everyone,</p>
<p>I&#8217;m posting this blog article due to the fact I had this problem and never found a solution online. With the help of Pat Allen and the ThinkingSphinx google group I was able to find a solution. <strong> My problem had nothing to do with not compiling using (&#8211;with-pgsql) it was far more obscure</strong>. I&#8217;m using ThinkingSphinx as a search tool in my Ruby on Rails application. This was my first Mac and when it came to indexing sphinx I would get the following error&#8230;</p>
<div id="code_block">
using config file &#8216;/Users/Chris/obilling/config/<br />
development.sphinx.conf&#8217;&#8230;<br />
indexing index &#8216;account_core&#8217;&#8230;<br />
ERROR: source &#8216;account_core_0&#8242;: unknown type &#8216;pgsql&#8217;; skipping.<br />
ERROR: index &#8216;account_core&#8217;: no valid sources configured; skipping.<br />
distributed index &#8216;account&#8217; can not be directly indexed; skipping.
</div>
<p>The problem was initially created due to the fact I had tried to install sphinx using macports (sudo port install sphinx). After the macport install things weren&#8217;t working properly so I did a manual install using the following resource as a guide (<a href="http://mediumexposure.com/2009/05/01/installing-sphinx-postgres-leopard"></a>). All of the articles I found said the problem was the fact I didn&#8217;t compile using ./configure &#8211;with-pgsql &#8211;without-mysql. This wasn&#8217;t the case as you can see in the resource I provided, I did compile it with pgsql support and the ./configure supported that. It all looked fine. I spent the next week working with Pat Allen and the ThinkingSphinx google group to come up with the solution.</p>
<p>I&#8217;m not sure if every step here is required, but I will outline the steps I followed&#8230;</p>
<p>First I checked to see if &#8220;searchd&#8221; was located in the opt/local/bin/ folder or in the /usr/local/bin folder. </p>
<div id='code_block'>
From the terminal&#8230;</p>
<p>which searchd
</p></div>
<p>My output showed opt/local/bin/ which indicated it was still using the macports install.</p>
<p>I then went about renaming these files&#8230;</p>
<div id="code_block">
cd /opt/local/bin/<br />
sudo mv searchd searchdold<br />
sudo mv indexer indexerold
</div>
<p>I then uninstalled the macports install&#8230;</p>
<div id="code_block">
sudo port uninstall sphinx
</div>
<p><strong> and finally&#8230;</strong> I re-installed sphinx and the proper libraries manually using the following resource&#8230;<br />
<a href="http://mediumexposure.com/2009/05/01/installing-sphinx-postgres-leopard">Installing Sphinx with Postgres on Leopard</a></p>
<p>Many thanks to Maxim Chernya @ Medium exposure for writing a great article on the installation process. </p>
]]></content:encoded>
			<wfw:commentRss>http://railstrip.ourgreatjourney.com/sphinx-mac-postgresql-unknown-type-pgsql-skipping/feed/</wfw:commentRss>
		</item>
		<item>
		<title>RAILS + ThinkingSphinx + 2 Models = Search Results for both</title>
		<link>http://railstrip.ourgreatjourney.com/rails_thinkingsphinx_2_models/</link>
		<comments>http://railstrip.ourgreatjourney.com/rails_thinkingsphinx_2_models/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 01:38:49 +0000</pubDate>
		<dc:creator>Chris Sund</dc:creator>
		
		<category><![CDATA[Rails Stuff]]></category>

		<category><![CDATA[RAILS + ThinkingSphinx + 2 Models = Search Results for both]]></category>

		<guid isPermaLink="false">http://railstrip.ourgreatjourney.com//?p=1</guid>
		<description><![CDATA[


Hey everyone,
This is my first Ruby on Rails article, and I&#8217;m excited to contribute something to the community (I hope).  I decided to write this article due to the fact I had a heck of a time finding this information myself. I&#8217;m not claiming to know everything here, just everything I know. I am [...]]]></description>
			<content:encoded><![CDATA[<p><em></em></p>
<div>
<p><em></em></p>
<p>Hey everyone,</p>
<p>This is my first Ruby on Rails article, and I&#8217;m excited to contribute something to the community (I hope).  I decided to write this article due to the fact I had a heck of a time finding this information myself. I&#8217;m not claiming to know everything here, just everything I know. I am open for suggestions, and comments. I am simply trying to help someone avoid all the hassle I had as a noob with &#8220;ThinkingSphinx/Rails&#8221;. Here&#8217;s what it&#8217;s all about.</p>
<p>(PS, I&#8217;m using PostgreSQL for my database, but that shouldn&#8217;t matter with this example)</p>
<p>Lets say you need the ability to search at least 2 models in your project and have ThinkingSphinx (TS) return your search results with information from both models. In my case I have an Account model with account information, and then a whole seperate Name model with the name information that is associated with each account.</p>
<p>Example&#8230;</p>
<p><strong>account.rb</strong></p>
<div id="code_block"><em>class Account &lt; ActiveRecord::Base</em></p>
<p>has_many :names, :dependent =&gt; :destroy</p>
<p># Thinking Sphinx Search Indexes</p>
<p>define_index do</p>
<p>indexes s_account, :sortable =&gt; true</p>
<p>indexes s_account_no</p>
<p>indexes names.name, :as =&gt; :account_name</p>
<p>end</p></div>
<p><strong>name.rb</strong></p>
<div id="code_block"><strong><span style="font-weight: normal;"><em>class Name &lt; ActiveRecord::Base</em></span></strong></p>
<p><strong><span style="font-weight: normal;">belongs_to :account</span></strong></p>
<p># Thinking Sphinx Search Indexes</p>
<p>define_index do</p>
<p>indexes account.s_account, :sortable =&gt; true</p>
<p>indexes account.s_account_no</p>
<p>indexes name, :as =&gt; :account_name</p>
<p>end</p>
<p><strong><span style="font-weight: normal;"><br />
</span></strong></div>
<p>A misconception I had when I started was the fact that I had to setup my search criteria in either my &#8220;Accounts&#8221; controller or my &#8220;Name&#8221; controller. This in fact isn&#8217;t true. After a bunch of trial and error and misunderstanding I found out that you can setup your search criteria in a seperate controller and model. I  called mine &#8220;Results&#8221;.   So to keep everything simple I will outline my rails files below, and try to provide some insight as to why I did it that way. The truth of the matter is however&#8230;. I did it this way because it worked.  I would love comments from anyone that feels they have a better way.</p>
<p>I already outlined my model files above, so here&#8217;s the rest of the info&#8230;</p>
<p><strong>ROUTES FILE </strong>(I added the following line)</p>
<div id="code_block">map.resources :results, :collection =&gt; {:search =&gt; :get}</div>
<p><strong>APPLICATION TEMPLATE </strong></p>
<p><em>viewslayoutsapplication.html.erb</em></p>
<p><em></em></p>
<div id="code_block"><em><span style="font-style: normal;">&lt;% form_tag search_results_path, :method =&gt; :get do %&gt;</span></em></p>
<p><em></em></p>
<p><span style="font-style: normal;">&lt;div id=&#8221;search&#8221;&gt;</span></p>
<p><span style="font-style: normal;">&lt;%= text_field_tag :search, params[:search], :class =&gt; &#8216;text&#8217; %&gt;</span></p>
<p><span style="font-style: normal;">&lt;%= submit_tag &#8216;Search&#8217;, :class =&gt; &#8216;button&#8217; %&gt;</span></p>
<p><span style="font-style: normal;">&lt;/div&gt;</span></p>
<p><span style="font-style: normal;"><br />
</span></div>
<p><strong>CONTROLLERS:</strong></p>
<p><strong>accounts_controller</strong></p>
<p>I did nothing to this controller to make it work.</p>
<p><strong>names_controller</strong></p>
<p>again, I did nothing to this controller</p>
<p><strong>results_controller</strong> <em>(I created this specifically for searching)</em></p>
<div id="code_block"><em><span style="font-style: normal;">class ResultsController &lt; ApplicationController</span></em></p>
<p><em><span style="font-style: normal;">def search</span></em></p>
<p><em></em></p>
<p><span style="font-style: normal;">@results = ThinkingSphinx::Search.search(params[:search],</span></p>
<p><span style="font-style: normal;">:classes =&gt; [Account,Name])</span></p>
<p><span style="font-style: normal;">respond_to do |format|</span></p>
<p><span style="font-style: normal;">format.html #calls the search.html.erb (viewsresultssearch.html.erb)</span></p>
<p><span style="font-style: normal;">end</span></p>
<p><span style="font-style: normal;">end</span></p>
<p><span style="font-style: normal;">end</span></p>
<p><strong><br />
</strong></div>
<p><strong>VIEW FILES</strong></p>
<p><em>viewsresultssearch.html.erb</em></p>
<div id="code_block"><em><span style="font-style: normal;">&lt;%- @results.each do |result| -%&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;% if result.class == Account %&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;br&gt;&lt;%= render :partial =&gt; &#8216;accounts/results&#8217;, :locals =&gt; {:account =&gt; result } %&gt;&lt;br&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;% elsif result.class == Name %&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;%= render :partial =&gt; &#8216;names/results&#8217;, :locals =&gt; {:name =&gt; result } %&gt;&lt;br&gt;&lt;br&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;% end %&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;%- end -%&gt;</span></em></p>
<p><em><span style="font-style: normal;">&lt;%= will_paginate @results %&gt;</span></em></p>
<p><em> </em></div>
<p><em>viewsaccounts_results.html.erb</em></p>
<p><em> </em></p>
<div id="code_block">Account: &lt;%= link_to account.s_account_no, edit_account_path(account) %&gt;</div>
<p>viewsnames_results.html.erb</p>
<div id="code_block">Name: &lt;%=name.name%&gt;</div>
</div>
<p style="font-style: normal;">When I was trying to find this information it didn&#8217;t make sense to me that I had to render a partial per model. After I set it up, and was able to see the results it seemed to work great. I just got it all setup, and I&#8217;m sure I will do some tweaking, but I was eager to post this blog before I got too lazy, or decided I wasn&#8217;t qualified yet to post anything about ThinkingSphinx. I&#8217;m not representing myself as qualified in this area I simply want to add one more resource for someone else to look at. If you have a better idea, or would like to add a comment, please do so.</p>
<p><img src="http://www.ourgreatjourney.com/wp-content/uploads/2009/04/example1.png" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://railstrip.ourgreatjourney.com/rails_thinkingsphinx_2_models/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
