Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

anso's Profile

GitHub User: anso

Comments by



Need some help on this

I wiould like to do something like that :

ruby{:profile_last_name_or_profile_first_name_cont_any=> 'jane doe'.split(' ')}).result

the SQL generated is the following

"SELECT \"users\".* FROM \"users\" LEFT OUTER JOIN \"profiles\" ON \"profiles\".\"user_id\" = \"users\".\"id\" WHERE (((\"profiles\".\"last_name\" ILIKE '%jane%' OR \"profiles\".\"last_name\" ILIKE '%doe%') OR (\"profiles\".\"first_name\" ILIKE '%jane%' OR \"profiles\".\"first_name\" ILIKE '%doe%')))"

which returns the expected results... But how to implement this request in my search form (in my view) and/or in my controller ?

My search form is :

<%= search_form_for @q, url: search_cockpit_users_path, method: 'post', id: 'users-search-form', class: 'span3 pull-right' do |su| %>
      <%= su.text_field :profile_last_name_or_profile_first_name_or_email_cont_any, :placeholder => 'full name or email contains' %>
      <%= su.submit 'Search', :name => nil, :class => 'btn ' %>
  <% end %>

As it is the SQL returned is

"SELECT \"users\".* FROM \"users\" LEFT OUTER JOIN \"profiles\" ON \"profiles\".\"user_id\" = \"users\".\"id\" WHERE (((\"profiles\".\"last_name\" ILIKE '%jane doe%') OR (\"profiles\".\"first_name\" ILIKE '%jane doe%')))"

but how to implement the split(' ') to have the expected SQL ?

Any help (and a bit of explanation) would be great, documentation is a bit light on the subject...


the requested 2D array expected by DataTables should be read with ' " ' (double quotes) around the right side of the pair for each attributes



It appears that the JSON array returned is not what is expected by DataTables.

Let say for a model User where mapping returns, user.last_name, user.first_name,

the returned JSON is

aaData: [[1, DOE, John,,],[7, BAXTER, Bill,],[15, BROWN, Bob,],...]

wich is a one dimension array, and the 2 dimensions arraay expected by DataTables (for the aaData part) should be for the same set of data

aaData: [{"id":1, "last_name":DOE, "first_name":John, "email",},{"id":7, "last_name":BAXTER, "first_name":Bill, "email"],{"id":15, "last_name":BROWN, "first_name":Bob, "email"},...]

So if it displays well in your example it throw errors when filtering server-side with an error "JSON data from server could not be parsed. This is caused by a JSON formatting error"

Is there anybody who knows how to return the well formatted JSON ?
Any help would be appreciate



link_to("Delete", product, method: :delete, data: { confirm: 'Are you sure?' })



Hello Pramsay
I know this post is a bit old but did you solved your problem ? I'm facing the same wall and can't find solution


I have a dataTable with nested models. I use server side processing and all works fine (search on multiple columns, sorting).

Now I need to add multiple row selection and send selected objects ids to my controller.

But I can't implement the multiple row selection. I followed the example on "". I changed my file to users.js to not have to mess with CoffeeScript.

Now when the page loads I have an error "reference error : aSelected is not defined" in the "fnRowCallBack" function, I see the datas in the table and the 'processing indicator'...

Any help on this would be very appreciated

By the way, the example provided in uses function which is obsolete since version 1.7, I changed it to '.on'