Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

anso's Profile

GitHub User: anso

Comments by

Avatar

Hello

Need some help on this

I wiould like to do something like that :

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

the SQL generated is the following

ruby
"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 :

ruby
<%= 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

ruby
"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...
Cheers

Avatar

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

Avatar

Hello

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

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

the returned JSON is

ruby
aaData: [[1, DOE, John, doe@example.com,],[7, BAXTER, Bill, baxter@example.com],[15, BROWN, Bob, brown@example.com],...]

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

ruby
aaData: [{"id":1, "last_name":DOE, "first_name":John, "email":doe@example.com,},{"id":7, "last_name":BAXTER, "first_name":Bill, "email":baxter@example.com],{"id":15, "last_name":BROWN, "first_name":Bob, "email":brown@example.com},...]

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

Avatar

Try

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

Cheers

Avatar

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

Avatar

Hello
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 "http://datatables.net/release-datatables/examples/server_side/select_rows.html". I changed my users.coffee.js 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
Cheers

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