2

I'm checking mercury editor https://github.com/jejacks0n/mercury on small project.

These is my routes.rb file

Myapp::Application.routes.draw do
  mount Mercury::Engine => '/'
  scope '(:locale)' do
    resources :post
  end
end

My post url are:

http://localhost:3000/es/posts/1
http://localhost:3000/en/posts/2
http://localhost:3000/de/posts/3
.
.
.

My mercury routes:

Routes for Mercury::Engine:
mercury_editor  /editor(/*requested_uri)(.:format)        mercury#edit
                /mercury/:type/:resource(.:format)        mercury#resource
                /mercury/snippets/:name/options(.:format) mercury#snippet_options
                /mercury/snippets/:name/preview(.:format) mercury#snippet_preview

I'm try something like:

<%= link_to 'Edit', "/editor" + request.path %>

but I get a wrong url http://localhost:3000/editor/es/posts/2.

can someone say me how add a specify path to my routes for something like:

http://localhost:3000/es/editor/posts/1 or http://localhost:3000/editor/posts/1

hyperrjas
  • 10,666
  • 25
  • 99
  • 198
  • What do you mean by "I get a wrong url" ? Does this url work but you don't like how it looks ? Or does the url not work at all ? For what it's worth I've just been in the same case you've been and ended up doing just what you did. And it's all working fine with that url `http://localhost:3000/editor/es/posts/2` – Jeremy F. May 18 '13 at 12:41

1 Answers1

0

Replace <%= link_to 'Edit', "/editor" + request.path %> with

<%= link_to 'Edit', request.path.gsub(/^\/((\w)+)/, '/\1/editor') %>

to get http://localhost:3000/es/editor/posts/1

Or

Replace <%= link_to 'Edit', "/editor" + request.path %> with

<%= link_to 'Edit', request.path.gsub(/^\/((\w)+)/, '/editor') %>

to get http://localhost:3000/editor/posts/1

even you can define a helper method like

def mercuryfied_url(with_locale = true)
  if with_locale 
    request.path.gsub(/^\/((\w)+)/, '/\1/editor')
  else
    request.path.gsub(/^\/((\w)+)/, '/editor')
  end
end

then call

<%= link_to 'Edit', mercuryfied_url %>

to get http://localhost:3000/es/editor/posts/1

Or

   <%= link_to 'Edit', mercuryfied_url(false) %>

to get http://localhost:3000/editor/posts/1

Hope that helps :)

Muntasim
  • 6,689
  • 3
  • 46
  • 69