Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery script behaving differently when unobtrusive than when inside the rails view
    text
    copied!<p>I have this in my view</p> <pre><code>&lt;script type='text/javascript'&gt; $(function(){ $('#users').click(function(){ alert($("tr[aria-selected=true] td:first").html()) }) }) &lt;/script&gt; </code></pre> <p>And inside my users.js</p> <pre><code>$(function(){ $('#users').click(function(){ alert($("tr[aria-selected=true] td:first").html()) }) }) </code></pre> <p>Having them,obviously not at the same time,gives me different results Basically I'm trying to retrieve the ID of the selected row finding it attr value.\</p> <p>With the unobtrusive way right after loading the page I'd get "null" on my first click on a row and then every time I hit a row shows me the value that I clicked previously...TWICE!. But when keeping the script inside my view I get the result I want.</p> <p>What am I doing wrong?</p> <p>EDIT:</p> <p>My view</p> <pre><code>&lt;%=raw jqgrid("List of users", "users", "/users", [ { :field =&gt; "id", :label =&gt; "id",:width =&gt; 50 }, { :field =&gt; "username", :label =&gt; "username",:width =&gt; 120,:editable =&gt; true }, { :field =&gt; "email", :label =&gt; "email",:width =&gt; 120,:editable =&gt; true }, { :field =&gt; "name", :label =&gt; "name",:width =&gt; 100,:editable =&gt; true }, { :field =&gt; "lastname", :label =&gt; "lastname",:width =&gt; 100,:editable =&gt; true }, { :field =&gt; "groups", :label =&gt; "roles",:width =&gt; 180} ] , {:add =&gt; true,:edit =&gt; true,:delete =&gt; true,:error_handler =&gt; "s",:inline_edit =&gt; 'true',:edit_url =&gt; post_data_users_url,:sortable_rows =&gt; 'true'} ) %&gt; &lt;p&gt;&lt;%= link_to "Edit roles",roles_path%&gt; &lt;%= link_to "| Edit user",{:action =&gt; 'edit'},{:class =&gt; 'editLink hide'}%&gt;&lt;/p&gt; &lt;script type='text/javascript'&gt; $(function(){ var _last = new String() $('#users').click(function(){ _last = $("tr[aria-selected=true] td:first").html() $(".editLink").attr("href","/users/edit/"+ _last) $(".editLink").addClass('show') }) }) &lt;/script&gt; </code></pre> <p>My layout</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;UserManager&lt;/title&gt; &lt;%= stylesheet_link_tag "application", :media =&gt; "all" %&gt; &lt;%= javascript_include_tag "application" %&gt; &lt;%= csrf_meta_tags %&gt; &lt;%=jqgrid_javascripts%&gt; &lt;%=jqgrid_stylesheets%&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;%if flash[:notice]%&gt; &lt;p&gt;&lt;%= flash[:notice]%&gt;&lt;/p&gt; &lt;%end%&gt; &lt;%if current_user%&gt; Logged in as &lt;%= current_user.username%&gt; | &lt;%= link_to 'logout', log_out_path%&gt; &lt;%end%&gt; &lt;/div&gt; &lt;%= yield %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The way I see it...nothing special there</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload