Adding Hash parameter in the URL Rails Routes

后端 未结 2 1123
忘掉有多难
忘掉有多难 2020-12-13 16:51

How to add a hash parameter in link_to. I need to generate a URL something like this..

/p/generate/#sometext

This is how my code looks now.

相关标签:
2条回答
  • 2020-12-13 17:14

    This is how you would usually do it:

    link_to "Click", my_path(:anchor => "sometext")
    

    Your routes don't have much to do with it, since the anchor part (#something) is not transferred to the server, it's a pure client-side thing.

    0 讨论(0)
  • 2020-12-13 17:19

    I recognize this is an old post, but I thought I would contribute my recent discovery:

    <%= link_to "New Person", polymorphic_path([:new, person], anchor: "profile") %>
    

    See the API Docs for details.

    0 讨论(0)
提交回复
热议问题