<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1080</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1080" rel="self"/>
  <title>nakajima</title>
  <updated>Sat Oct 18 22:40:21 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55572</id>
    <published>2008-10-18T22:40:21-07:00</published>
    <title>[Ruby] On Generating tables with a helper method</title>
    <content type="html">&lt;p&gt;You can use a partial to clean this up a bit, though it doesn't seem totally bad as is.&lt;/p&gt;

&lt;pre&gt;## view [html_rails]
&amp;lt;table&amp;gt;
  &amp;lt;thead&amp;gt; &amp;lt;th colspan=&amp;quot;2&amp;quot;&amp;gt;Groups&amp;lt;/th&amp;gt;&amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    &amp;lt;%= render :partial =&amp;gt; &amp;quot;group&amp;quot;, :collection =&amp;gt; @groups %&amp;gt;
  &amp;lt;/tbody&amp;gt;
  &amp;lt;tfoot&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;%= will_paginate @groups %&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/tfoot&amp;gt;
&amp;lt;/table&amp;gt;

## _group.html.erb [html_rails]
&amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;&amp;lt;%= image_tag group.picture %&amp;gt;&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;
    &amp;lt;h6&amp;gt;&amp;lt;%=link_to h(group.name), group %&amp;gt;&amp;lt;/h6&amp;gt;
    &amp;lt;%= h group.description %&amp;gt;
  &amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&lt;/pre&gt;</content>
    <author>
      <name>nakajima</name>
      <email>patnakajima@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/538-generating-tables-with-a-helper-method/refactors/55572" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55243</id>
    <published>2008-10-16T03:27:14-07:00</published>
    <title>[Ruby] On select tag with a selected option</title>
    <content type="html">&lt;p&gt;@adam: I see. Cool.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>nakajima</name>
      <email>patnakajima@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/533-select-tag-with-a-selected-option/refactors/55243" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55226</id>
    <published>2008-10-16T00:35:53-07:00</published>
    <title>[Ruby] On Query String to Hash</title>
    <content type="html">&lt;p&gt;If you just want the query params, here's one.&lt;/p&gt;

&lt;pre&gt;## quick and dirty [ruby]
class String
  query = split(/\?/)[-1]
  parts = query.split(/&amp;amp;|=/)
  Hash[*parts]
end&lt;/pre&gt;</content>
    <author>
      <name>nakajima</name>
      <email>patnakajima@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/359-query-string-to-hash/refactors/55226" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55224</id>
    <published>2008-10-16T00:25:20-07:00</published>
    <title>[Ruby] On select tag with a selected option</title>
    <content type="html">&lt;p&gt;I like Adam's idea of using fields_for. I'd go a step further and pull the options into a helper method as well (I don't like seeing #collect inside an erb tag). Also, I'm not quite sure why there's a need for an OpenStruct there.&lt;/p&gt;

&lt;p&gt;For the selected_option method you pasted, I thought a more meaningful name would be worthwhile, so I renamed it to current_category. The implementation I added is pretty simple, albeit crude. It definitely makes assumptions about your params that may or may not be a good idea, but I'll leave that up to you.&lt;/p&gt;

&lt;pre&gt;## In your courses_helper.rb [ruby_on_rails]
module CoursesHelper
  def category_options
    [[_(&amp;quot;V&#197;&#161;echny kategorie&amp;quot;), &amp;quot;&amp;quot;]] + @course_categories.collect {|d| [ d.title, d.id ] }
  end
  
  def current_category
    params[:search][:course_category_id] rescue nil
  end
end

## View [html_rails]
select(:search, :course_category_id,  category_options, :selected =&amp;gt; current_category)&lt;/pre&gt;</content>
    <author>
      <name>nakajima</name>
      <email>patnakajima@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/533-select-tag-with-a-selected-option/refactors/55224" rel="alternate"/>
  </entry>
</feed>

