Rails-4 ajax and Jquery with link_to used for open jquery-ui-dialog

Hi,

In my application, with ajax (remote => true) actived, i can not call
dialog box via jquery-ui to be open normally.
In fact, the call works, but:

In the body, there is a sort/search div part (this one refer to a
sort_controler.rb file, who redirect to my movie_controler.rb after do
his job… this part serv for filter like “title” or “date” order of
view, and/or “style of movie” to be listed, etc… all this is inside a
form_for construction), follow by a paginate (kaminari) div (render
partial part… this one works perfectly with remote ajax control,
follow by a movie list (each movie is represented by a title and an
linked image (when you click on the image of the jacket, a dialog bo
need to be open with all the caracteristic of the movie concerned by the
choice).

Now, due to the render on javascript to my index.js file inside my
movie_controller.rb file (for act the remote ajax to works), if i click
on the linked jacket image, the box appears (efect no have time to be
finish), and cancel quickly because all the process (respond_to =>
format js => render my index.js file) of render call to refresh the
remote ajax part. So, sure, the render partials are all render again. If
i “sort” (for exemple by select “action movies” to be listed, and submit
it), the kaminari paginate remoted works, the remote ajaxed list of
movies appears good… but if i click on a linked movie jacket, i go
back to the first loaded page.

Then, my problem is that i don’t know (and not find… documentation on
link_to and render is really poor on the API of Rails) how to attribute
a tag or fixed data to be read to my link_to call for be able to choose
in my controller to redirect, not on my index.js file, but on my
jacket_dialog.js file only (with a condition test for exemple). If i can
do it, my problem (i think) will be resolved.
When i click on the link_to, i see on the console that it looks like i
click on my submit button for sort… the commit in params is the same.
So… how to change this commit (like that i could test by this way to
redirect correctly) ?

thanks for help

On 21 June 2014 10:48, jerome jerome [email protected] wrote:

Then, my problem is that i don’t know (and not find… documentation on
link_to and render is really poor on the API of Rails) how to attribute
a tag or fixed data to be read to my link_to call for be able to choose
in my controller to redirect, not on my index.js file, but on my
jacket_dialog.js file only (with a condition test for exemple). If i can
do it, my problem (i think) will be resolved.

Are you just asking how to pass extra parameters to be passed in the
url in link_to? If so then it would have been better just to ask
that. You have not showed us the current code for your link_to but
assuming it is something like
<%= link_to ‘Sometext’, some_path(…) %>
then just add the extra parameter to the path method so it becomes
some_path(… , :some_name >= “some value” )
which will add some_name to the params hash (via the url) so you can
access it in the controller.

Colin

On 21 June 2014 16:14, jerome jerome [email protected] wrote:

Thanks, i arrived to past by this way some params. And from the
controller, now, with request.query_string(), i can read it easy. So, i
pass by “?someparams=an_target” by the link.

No need to do that, just use params[:someparams]

did you have an idea ?

Sorry, I can’t help with this problem.

Colin

Thanks, i arrived to past by this way some params. And from the
controller, now, with request.query_string(), i can read it easy. So, i
pass by “?someparams=an_target” by the link.
And then, i can redirect on the jquery/coffee file has i would like.

BUT…
i don’t know why, my jquery-ui-dialog don’t want to open. The target is
clearly identified, the dialog div with its id (the target… and i can
see the target correctly named with an alert for check: OK) is in place
(view by firebug)… why this don,'t want to open ?

so… before make all this runing by ajax (remote: true), dialogs bpxs
opened well. Maybe i forget something.

did you have an idea ?

ok, that’s works fine.
and so, i need to include jquery-ui-all inside my application.js file to
see it working.
Also, write my js files with coffeescript that’s work fine (extend by
.js.coffee… and sometimes by .erb more works fine too).

For render it easy, i include in a span: onclick=“window.open_me(this)”,
and then, in my js file (write under coffeescript) write inside my
assets/javascripts directory, i create my referenced fonction open_me
for create and pass for each the diolg box params. in an other js file,
i tell him to destroy them when an other search has been asked.
For automatic (AJAX) render (without push the submit button) when a
selection trouth select selectors, in
the same js file inside the assets pipeline, i add some event function
for call a submit targeted on my sort form (this form is remote:
true…).
Like this:
$(document).on ‘change’, ‘.selectors’, ->
$("#new_sortmovie").submit()
return

my index.js file who is on my views/movies directory do the job for
destroy the old dialog constructors and render the pagination (kaminari)
partial and also my movie list render partial.
Like this:
window.open_me()
$(".jacket_dialog").dialog(‘destroy’)
$("#affichage_movies").html(’<%= escape_javascript(render partial:
“/movies/movies”, object: @movies) %>’)
$("#info_movies").html(’<%= escape_javascript(render partial:
“/movies/info_paginate”, object: @movies) %>’)

For sugar… i add on my search input a function to delay my “keyup”
events…
Like this:
go = null if !go
$(document).on ‘keyup’, ‘.text_search’, ->
clearTimeout(go)
go = setTimeout( ->
$("#new_sortmovie").submit()
1000)
return

And i’m happy… all works perfectly.

So… i’m a newbie on rails and i need to clean my code (some of my sort
function is inside my movies_controller… i think it will be beter to
do it by my sortmovies helper… but i’m not sure.

Thanks for help.
When all will be “clean” (i hope), i will pass my git directory for help
other newbies (because now… i think it would not be a good exemple due
to a dirty code).