Note that there are some explanatory texts on larger screens.

plurals
  1. PORails3: Nested Restful routes with to_param are inversed
    primarykey
    data
    text
    <h1># Explaining the context</h1> <pre class="lang-rb prettyprint-override"><code>puts "I am learning Rails, building a simple forum application." puts "I am pretty satisfied to where I got so far but routes... " puts "...still figuring them out." puts "Been 2 days trying all sorts of things." puts "This is where I am now, and something is not working as expected." puts "Any help/pointers would be appreciated! :)" </code></pre> <h1># config/routes.rb</h1> <pre class="lang-rb prettyprint-override"><code>scope "/helpcenter" do resources :cat, :controller =&gt; "forums", :as =&gt; :forums do resources :topics , :controller =&gt; "forum_topics", :as =&gt; :topics resources :posts, :controller =&gt; "forum_posts", :as =&gt; :posts end end match "/helpcenter" =&gt; "forums#index", :as =&gt; :forums </code></pre> <h1># app/models/forum.rb</h1> <pre class="lang-rb prettyprint-override"><code>class Forum &lt; ActiveRecord::Base def to_param "#{id}-#{name.parameterize}" end end </code></pre> <h1># app/models/forum_topic.rb</h1> <pre class="lang-rb prettyprint-override"><code>class ForumTopic &lt; ActiveRecord::Base def to_param "#{id}-#{name.parameterize}" end end </code></pre> <h1># app/controllers/forums/show.hmtl.erb</h1> <pre class="lang-rb prettyprint-override"><code>link_to @forum_topic.name, forum_topic_path(@forum_topic) # OR link_to @forum_topic.name, @forum_topic </code></pre> <h1># What is being generated by link_to :</h1> <pre class="lang-rb prettyprint-override"><code>"/helpcenter/cat/1-first-topic/topics/1-first-forum" </code></pre> <h1># What I expected to see (because topics should be in forums):</h1> <pre class="lang-rb prettyprint-override"><code>"/helpcenter/cat/1-first-forum/topics/1-first-topic" </code></pre> <h1># What am I doing wrong?</h1> <pre class="lang-rb prettyprint-override"><code>puts "Thanks!" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload