Rails link to current page and passing parameters to it

前端 未结 8 999

I am adding I18N to my rails application by passing the locale using url params. My urls are looking like http://example.com/en/users and http://example.com/ar/users (for th

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 00:26

    A much quicker avenue - and convenient if you have many parameters that change in different places... avoid the clutter with an anchor tag that just merges the new locale param to the existing ones (and actually killing the old locale param).

    <%= link_to "ру", request.params.merge( locale: 'ru' ) %>
    

    But yes, one needs to whitelist parameters at that point, according to application's context.

提交回复
热议问题