Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing: resource_path or resource_url?

When you do map.resources on a model, it generates a bunch of routing helpers:

resource_path(@resource)
resource_url(@resource)
new_resource_url
etc.

What's the difference between using _path and _url? From what I've tried it doesn't seem to make any difference.

like image 757
Karl Avatar asked Mar 01 '23 05:03

Karl


1 Answers

foo_url includes the domain and protocol. foo_path only outputs the relative path.

>> foo_url(:id => 1)
http://localhost:3000/foo/1

>> foo_path(:id => 1)
/foo/1

Most of the time, you want "_path" but you have the choice.

like image 101
jdl Avatar answered Apr 28 '23 22:04

jdl