Skip to content

Instantly share code, notes, and snippets.

@devinmrn
Created June 26, 2011 01:29
Show Gist options
  • Save devinmrn/1047127 to your computer and use it in GitHub Desktop.
Save devinmrn/1047127 to your computer and use it in GitHub Desktop.
Sort on fields from other column. Receive ActiveRecord::StatementInvalid
Error Log:
,,,ruby
2011-06-26T01:25:07+00:00 app[web.1]: Started GET "/admin/problems?sort=user_address&sort_reverse=false" for 76.114.20.226 at 2011-06-25 18:25:07 -0700
2011-06-26T01:25:07+00:00 app[web.1]:
2011-06-26T01:25:07+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "{"
2011-06-26T01:25:07+00:00 app[web.1]: LINE 1: ...T "problems".* FROM "problems" ORDER BY problems.{User(id: ...
2011-06-26T01:25:07+00:00 app[web.1]: ^
2011-06-26T01:25:07+00:00 app[web.1]: : SELECT "problems".* FROM "problems" ORDER BY problems.{User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, created_at: datetime, updated_at: datetime, first_name: string, last_name: string, location: string, address: string, postal_code: string, city: string, state: string, country: string, latitude: float, longitude: float, account_status: string)=>:address} asc LIMIT 20 OFFSET 0):
```
Rails Admin initalizer
```ruby
config.model Problem do
list do
field :user_first_name, :string do
formatted_value do
bindings[:object].user.try :first_name
end
sortable do
{ User => :first_name }
end
searchable do
{ User => :first_name }
end
end
end
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment