简体   繁体   中英

Rails3: generate a URL with params from an Array

Starting fro this LINE:

link_to "delete", [:delete, :backend, @resource]

I want to generate a URL like this: /backend/pages/19/delete?locale=en

How can I add params to that array? Something like this:

link_to "delete", [:delete, :backend, @resource, :locale => :en]

This is the route.rb file:

namespace :backend do
    resources :pages do
        member do
            get :delete
        end
    end
end

Since, you have not shared the contents of routes.rb , I can't see how you have defined the route for /backend/pages/19/delete .

In order to pass query string in the link, you could do as shown below:

    <%= link_to 'delete', pathname_path(@resource, locale: "en") , method: :delete %>

where

Replace pathname with the named route for /backend/pages/19/delete defined in routes.rb .

If you want to include the locale in all the routes, read about Setting the Locale from the URL Params in Rails Guides.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM