title: Rails routing using custom attribute rather than table column
body: <p>Using Rails 4.2, I want to create a custom route using an <code>attr_accessor</code> rather than a table column, but I can't get the <code>resource_path</code> method to work.</p>
  
  <p>I want custom route like this: <code>/foos/the-title-parameterized-1</code> (where "<code>1</code>" is the <code>id</code> of the object). </p>
  
  <p><code>Foo</code> model:</p>
  
  <pre><code>#...
  attr_accessor :slug
  #dynamically generate a slug:
  def slug
    "#{self.title.parameterize[0..200]}-#{self.id}"
  end
  #...
  </code></pre>
  
  <p><code>routes.rb</code>:</p>
  
  <pre><code>get 'foos/:slug' =&gt; 'foos#show', :as =&gt; 'foo'
  </code></pre>
  
  <p><code>foos_controller.rb</code>:</p>
  
  <pre><code>def show
    @foo = Foo.find params[:slug].split("-").last.to_i
  end 
  </code></pre>
  
  <p>In my <code>show</code> view, when I use helper method <code>foo_path</code> it returns the route using the <code>id</code> of the object rather than the <code>slug</code> like this: <code>/foos/1</code>. Is it possible to get this helper method to use the accessor method? Am I off track with this approach?</p>
  
  <p>I would prefer to use <a href="https://github.com/norman/friendly_id" rel="nofollow noreferrer">Friendly Id</a> but I dont believe its possible without creating a <code>slug</code> column in my model table. I dont want to create a column because there are millions of records. </p>