Search code examples
ruby-on-railscarrierwaveprettyphoto

Rails prettyPhoto does not show photo with jquery (instead redirect to photo page)


i do all instruction for use prettyPhoto in https://github.com/hiq5/prettyphoto-rails.

and i do this to show a single photo( not gallery )

=link_to image_tag(photo.photo_url(:thumb).to_s, :alt => photo.name ,:class => "img-polaroid"), photo.photo_url, :rel => 'prettyPhoto'

but still redirect to photo url and show photo, and doesn't use jQuery to show it on the current page.

i check it with chrome development tools, there isn't any error.

i use haml to generate views (instead erb), and carrierwave to upload photos. by the way I use twitter bootstrap.

any help is appreciated.


Solution

  • in the documentation don't tell we should add the following code in bottom of body (html tag)

    so we should add the following code

    in haml

    %script{:charset => "utf-8", :type => "text/javascript"}
      $(document).ready(function(){
      $("a[rel^='prettyPhoto']").prettyPhoto();
      });
    

    in erb or html

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
            $("a[rel^='prettyPhoto']").prettyPhoto();
        });
    </script>