Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To solve your immediate problem, you'll want to add something like this to <code>routes.rb</code></p> <pre><code># config/routes.rb match "/causes/:cause_id/:slug/post/:id" =&gt; "causes#update_post", :via =&gt; 'put', :as =&gt; :update_post </code></pre> <p>And then you can generate the URL in your views like this...</p> <pre><code>link_to 'Update this post', update_post_path(@cause, @post) </code></pre> <p>...and access the parameters in your controller as <code>params[:id]</code> (for the post) and <code>params[:cause_id]</code> (for the cause).</p> <p>More generally, though, the way you are specifying your routes is pretty cumbersome, and I suspect you're making your life harder than it needs to be. If this were me, I would do something like</p> <pre><code># config/routes.rb resources :causes do resources :posts end </code></pre> <p>This would accomplish something pretty close to what you have now, the main difference being that it wouldn't contain slugs. I'm not sure why you need to have both slugs and IDs, maybe you could just identify your causes by their slugs? <a href="https://github.com/rsl/stringex" rel="nofollow">Stringex</a> is a good gem for generating slugs, and you can set it so that slugs are guaranteed to be unique.</p> <p>Here is the section of the Rails guide on nested resources <a href="http://guides.rubyonrails.org/routing.html#nested-resources" rel="nofollow">http://guides.rubyonrails.org/routing.html#nested-resources</a></p> <p>And here is a Railscast about using slugs with nested resources <a href="http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?view=comments" rel="nofollow">http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?view=comments</a></p> <p>Hope this helps.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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