Jquery + Rails

32 views
Skip to first unread message

Alfredo Barrero

unread,
May 7, 2014, 11:54:26 AM5/7/14
to rubyonra...@googlegroups.com
Can someone tell me any tutorial wich I could follow in order to learn Jquery with Rails?. I see many tutorias about Jquery but I don`t know how to render it in rails views.

I'm trying to do this but it does not work.

<%= image_tag current_user.avatar_file_name , :class => 'user-img_style', :id => 'jquery'%>

<script>
    $( "#jquery" ).click(function() {
        alert( "Handler for .click() called." );
    });
</script>

mike2r

unread,
May 7, 2014, 4:17:10 PM5/7/14
to rubyonra...@googlegroups.com
That should work.  I quickly tested it using a different image, obviously, but otherwise the same code.  it worked for me.  when it's not working for you, what exactly happens?  do you get any error messages in the log?  does the image appear as it's supposed to?

Alfredo Barrero

unread,
May 8, 2014, 5:51:20 AM5/8/14
to rubyonra...@googlegroups.com
Hi good morning, now it works. 

Could you please tell me how can I open a modal window with a form in order to do an AJAX request with Jquery?. 

What I need is, when the user click on the image a modal window appear with the option to change the current profile image. I’m trying to use $.get(‘users/_form.html.erb) but this is never showed. 

Thanks and regards. 

Alfredo. 



--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/dOPCMnsy8do/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c5e2d197-5484-4634-8419-80ab1f6095b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Davis, PhD

unread,
May 8, 2014, 7:52:09 AM5/8/14
to rubyonra...@googlegroups.com
jQuery is very much integrated with Rails. Try looking at Micheal Hartl's tutorial and completely work through it. You need the basics of the framework, coffeesript, and how it comes together. In general, you should not be using <script> in your views.

Alfredo Barrero

unread,
May 10, 2014, 2:07:27 PM5/10/14
to rubyonra...@googlegroups.com
Ok I'm working with Jquery, I really like it , it looks easy and powerful.

I have an issue here. I'm trying to change one CSS property from Jquery. This 'add-photo-mw' has pre-defined 'display:none'. Below is the code.

 <%= link_to 'Add photo', adding_photo_path(current_user), class:'css3button', :id => 'add-photo-mw'%>

When this link is tiggered <%= link_to 'Go to Gallery', loading_gallery_path, class:'css3button', :id => 'show-add' %> the following Jquery code is launched.

$(document).ready(function(){
    $('#show-add').click(function(){
        $('#add-photo-mw').css('display','inline');
    });
} );


Everything looks good, when the link is selected the link_tag is showed in the browser, but secods later the link is hide again. You know why is this happening?.

Thanks & regards.


Alfredo.
Reply all
Reply to author
Forward
0 new messages