Forum: Ruby on Rails controller, params, view, routing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alexandru C. (Guest)
on 2007-02-13 08:45
controller action - create - takes one param - parent_id and then
renders the view
In the view there's the following code:

<div id="breadcrumb">
    <%= link_to "Admin", {:controller => 'admin', :action => 'index'},
{:title => 'Admin'} %>
    <span>/</span>
    <%= link_to "Articles", {:controller => 'cms', :action => 'index'},
{:title => 'Articles'} %>
    <span>/</span>
    New article
</div>


<fieldset>
    <h2>Article</h2>
        <div class="required">
            <input type=hidden id='cms_article_parent_id'
name='cms_article[parent_id]' value='<%= params[:id]? params[:id] :0
%>'/>
</div>
</fieldset>

My problem.

If I use it like this, the urls will look something like
http://localhost:3000/admin/cms/create?parent_id=1
and this part of the breadcrumb

<%= link_to "Articles", {:controller => 'cms', :action => 'index'},
{:title => 'Articles'} %>

becomes this

<a href="/admin/cms/list" title="Articles">Articles</a>
instead of
<a href="/admin/cms" title="Articles">Articles</a>

and the params[:parent_id] is not accessible (nil).

If I define this in routes.rb
map.connect '/admin/cms/create/:parent', :controller => 'admin/cms',
:action => 'create', :parent => nil

the url looks like this

  http://localhost:3000/admin/cms/create/1

and the view display correctly.

Any ideea ?
This topic is locked and can not be replied to.