Usando dois slugs

2 views
Skip to first unread message

Vinicíus Luiz

unread,
Nov 5, 2009, 3:10:33 PM11/5/09
to rails-br
Olá pessoal,

em um projeto aqui to tentando fazer um slug de forma que a url fique
assim:
http://localhost:3000/pages/main/fragments/title

mas o máximo que consegui foi deixar assim:
http://localhost:3000/pages/main/fragments/1

na url, main e title sao os slugs do registro que tenho para um objeto
do tipo page.. o codigo ta no link http://gist.github.com/227334
problema é que não to conseguindo fazer o segundo slug (para
fragments) da forma como ta o primeiro (page). Se deixar do mesmo
jeito aparece o seguinte erro

ActionController::RoutingError in Pages#show

page_fragment_url failed to generate from
{:controller=>"fragments", :page_id=>#<Page id: 1, title: "Página
principal", slug: "main", created_at: "2009-11-05 19:44:55",
updated_at: "2009-11-05 19:44:55">, :id=>#<Fragment id: 1,
fragmentable_id: 1, fragmentable_type: "Page", title: "title", slug:
nil, body: "teste", created_at: "2009-11-05 19:48:53", updated_at:
"2009-11-05 19:48:53">, :action=>"show"}, expected:
{:controller=>"fragments", :action=>"show"}, diff: {:page_id=>#<Page
id: 1, title: "Página principal", slug: "main", created_at:
"2009-11-05 19:44:55", updated_at: "2009-11-05
19:44:55">, :id=>#<Fragment id: 1, fragmentable_id: 1,
fragmentable_type: "Page", title: "title", slug: nil, body: "teste",
created_at: "2009-11-05 19:48:53", updated_at: "2009-11-05 19:48:53">}

alguém tem alguma idéia ?????

Vinicius Luiz

unread,
Nov 5, 2009, 3:30:28 PM11/5/09
to rails-br
o erro nao esta em nenhum dos codigos que passei, esta na minha view

<% div_for fragment do %>
  <%= h(fragment.slug) %>
  <br/>
  <%= link_to 'apagar', [@page, fragment], :method => :delete, :confirm => 'confirma ?' %>|
  <%= link_to 'editar', [@page, fragment] %>
  <br/>
  <%= h(fragment.body) %>
<% end %>

não sei como montar o link!! to usando rotas alinhadas

  map.resources :fragments
  map.resources :pages, :has_many => :fragments

e o parametro id na realidade é o atributo slug do objeto. Como posso configurar o link para que seja montado a URL

page_fragment_path

passando a parametro slug do objeto ??????

<%= link_to 'editar', page_fragment_path(fragment.slug) %> <<<<<< assim da erro do mesmo jeito...

att,

Vinicius Luiz
Skype/Yahoo: vinicius.luiz
MSN: vinic...@hotmail.com
Gtalk: mcp.vi...@gmail.com
Twitter: http://twitter.com/vinicius_luiz
Blog: http://viniciusluizz.wordpress.com

----------------------------------------------

           Analista Desenvolvedor - TI                
CETAM Ltda. - Centro de Tecnologia da Amazônia

when there is no place in hell, the dead walked the earth!


2009/11/5 Vinicíus Luiz <mcp.vi...@gmail.com>

Vinicius Luiz

unread,
Nov 5, 2009, 3:38:31 PM11/5/09
to rails-br
so um detalhe, com o link configurado assim


<%= link_to 'editar', page_fragment_path(fragment.slug) %>

a url gerada fica assim

http://localhost:3000/pages/title/fragments/main

so que isso ta invertido, o correto era pra ser

http://localhost:3000/pages/main/fragments/title

notem a posição do main e do title desse ultimo link....
alguem que saque de rotas alinhadas para dar uma ajuda por favor

?????????


att,

Vinicius Luiz
Skype/Yahoo: vinicius.luiz
MSN: vinic...@hotmail.com
Gtalk: mcp.vi...@gmail.com
Twitter: http://twitter.com/vinicius_luiz
Blog: http://viniciusluizz.wordpress.com

----------------------------------------------

           Analista Desenvolvedor - TI                
CETAM Ltda. - Centro de Tecnologia da Amazônia

when there is no place in hell, the dead walked the earth!


2009/11/5 Vinicius Luiz <mcp.vi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages