Search code examples
ruby-on-railsruby-on-rails-3sortingransack

Ransack with sort_link for nested resources


I have setup a nested resource like /projects/1/tasks and want to use sort_link method.

With <%= sort_link @search, :taskname %> i expect /projects/1/tasks?q... but i do get /tasks?q....

Is this possible?


Solution

  • You can pass options to the sort_link helper, for example

    sort_link @search, :taskname, { :controller => tasks, action: "index", project_id: @project.id }
    

    where options can be anything that is accepted by the url_for helper

    see: https://github.com/ernie/ransack/blob/v0.6.0/lib/ransack/helpers/form_helper.rb