简体   繁体   中英

When is `_path_url` required when linking inside a Rails application?

When is it required to use _path_url instead of _path inside an application?

My understanding was that _path provides a relative path inside of a site, where _url is required when linking between different sites.

Source: Named routes _path vs _url

But I'm getting the below error in my application when linking to another page.

Error:

undefined method `users_show_path' for #<#:0x007fe12740c3a0> Did you mean? users_show_path_url

routes.rb

get '/user/:id/show', to: 'users#show', as: :users_show_path

Working link

<%= link_to 'Return', users_show_path_url(current_user), class: 'btn btn-default'  %>

Failing link

<%= link_to 'Return', users_show_path(current_user), class: 'btn btn-default'  %>

Adding _url was required to make it work.

I've never had this issue before in Rails development so I'm wondering if there is some routing technicality that might be causing it.

This is just a guess

<%= link_to 'Return', users_show_path_path(current_user), class: 'btn btn-default'  %>

Why do you need as: :users_show_path make it as: :users_show

Then your code will work otherwise you can use users_show_path_path which is funny..

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