4) %> And on my page. rb I want to show urls by th...">

Hard coding codes in Rails

Say I have this:

<%= link_to "My Big Link", page_path(:id => 4) %>

And on my page. rb I want to show urls by their permalink, so I use the standard:

 def to_param
    "#{id}-#{title.parameterize}"
 end

Now, when I click "My Big Link", it returns me to the correct page, but the URL in the address bar does not display the desired permalink. Instead, it just shows the standard:

wwww.mysite.com/pages/4 

Is it because I hardcoded the id in page_path? It also does not work if I use direct html, for example ..

<a href="/pages/4">My Big Link</a>

I would appreciate it if someone could test the same behavior and let me know if this is intended or not. I need the ability to hard code: id specify exact pages ...

+3
source share
3

---------------------- >

. . html:

<a href="/pages/4-great-title-here">My Big Link</a>

:

wwww.mysite.com/pages/4-great-title-here

. , !

-1

page_path (). , ( ), , to_param, .

<%= link_to "My Big Link", page_path(page) %>
+5

, id:

page_path(:id => 4)

, :

page_path(:id => "#{id}-#{title.parameterize}")

to_param? ?

+1

Source: https://habr.com/ru/post/1718969/


All Articles