New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two typos in the doc #468
Comments
@v5out thanks! For the code, I believe the doc is correct as is. However, in the console, underscores replace the period. See #431 and #450. It's true that it is confusing. If the parsing could be made to work with underscores everywhere, that could be a useful contribution. Could you let me know in what situation (code or console, Rails/Ruby/Ransack versions) you came across this? |
Thanks Jon, had not seen those issues and, like the others, didn't know about [skip ci] 'department_title' format works for me in the code, have not tried the console. If I use the 'department.title' format there's no error, the sort just doesn't work. Rails 4.1.5, Ruby 2.1.2, Ransack 1.4.1 (For completeness...using Kaminari 0.16.1 for pagination and Draper 1.4.0 for decorators.) My index.html.erb file looks like:
|
Thanks. With the period you would need to use |
No, 'departments.title' doesn't work either, no error, just doesn't sort. The associations I'm using are similar to the doc but are a bit different, as follows. Perhaps it is the "through" association that makes the difference?
|
As I commented on #13, the documentation is wrong. the sort link string appear to not map directly to sql. It works as |
@dgm I am unable to reproduce this. Could you please provide the information mentioned in the Contributing Guide please? |
Here's a basic rails app that implements the documentation. https://github.com/dgm/ransack-sort-demo As you can see, the links as documented do not work, but I provide other links that do. The basic misconception seems to be in thinking that 'the association is expressed as an SQL string' ... It most assuredly is not. It uses the same association name underscore attribute format as all the rest of the searchers. (minus a predicate like _cont). |
Could you begin by providing the basic info in the Contributing Guide so that we can try to reproduce your environment? It looks like you are using Rails 4.2 in the demo app, but no version of Ruby or Ransack is specified and it is not practical to have to guess. I'm not saying you're wrong, but I have to reproduce your environment and issue. |
The Gemfile and Gemfile.lock should have all that info. Rails 4.2, ruby 2.1 or ruby 2.2 , it won't matter. ransack (1.5.1) |
I don't see the Ruby version specified in the demo app. Are you encountering the issue with the latest Ransack release (1.6.3)? |
Gemfile.lock always has that info for rails apps. Anyway, no change on 1.6.3 |
And I don't think there should be any change - the current behavior is correct, it uses the existing association to generate the sort - which may include special conditions into the overall sql. sorting on a simple sql table.column is way too simplistic for what ransack actually does. The documentation is just wrong. |
How are you testing this? |
I meant to commit the sqlite database with that so the test data is there... pull the latest changes, run the rails server and look at http://localhost:3000/supervisors |
@dgm Thanks, I wasn't able to get sort_link's working on associations according to the documentation using the |
@dgm I experienced the same behavior in 1.6.6. I needed to do |
I know it's pouring oil on the fire at this point, but I experienced the same behavior with 1.7.0. The SQL doesn't work at all, in any form or pluralization, but a symbolized underscore works great. |
Thanks @UlyssesInvictus, could you provide actionable information to reproduce? Version of Active Record, Ruby, which database? Are you using Ransack via another gem like Active Admin? On the command line or in your app? |
The original issue is #13. I'd like to understand how/when people are having this issue. In the meantime, I've committed a change in the docs that provides both versions. |
As I see it, it is not an sql string at all, but the association, just like "Ransack objects elsewhere" as the removed part of your commit above said... if the association is a belongs_to, it will be singular, and underscores to seperate parts.... just like ransack objects elsewhere |
I agree that it should be like that, but have not been able to reproduce... only SQL-style strings work for sort links on associations for me. I don't use Active Admin or Simple Form -- all standard omakase Rails. Perhaps I'm doing something in my code that no one else is doing 🌵 This afternoon I have to step through the sort link code with byebug/pry to work on Ransack breaking with Rails master now that strong parameters inherit from ActionController::Parameters now. Lots of things are breaking from this... it's pretty bad. Perhaps I'll see what's going on with the associations while I'm at it. Otherwise will look through your example app above. |
Oh, sorry, forgot many crucial details--that's so odd that it breaks for you in the opposite way it breaks for everyone else. Anyways, I was running:
|
Thanks. Not sure it is the opposite for everyone else, 2 million downloads of Ransack (1 million in the past 12 months) and ten people mention a problem. It could have been people using Active Admin (which modifies the Ransack API) or using another database like Sequel instead of Active Record. But I'm willing to believe it might be something on my side until I really go through it. |
No, of course--should have clarified "everyone else [in this thread]." |
Ransack is great! Cleaning up a few typos in the doc would help a bit, too. The two that got me today were:
<%= content_tag :th, sort_link(@q, 'departments.title') %>
<%= content_tag :th, sort_link(@q, 'employees.last_name') %>
I believe those should be _ (underscores) instead of "." and supervisor belongs_to department so that should be 'department_title'.
The text was updated successfully, but these errors were encountered: