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
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 :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.