0

I have this link in view/users/show:

<%= link_to "Photos (#{@user.photos.count})", user_path(@user), id: "photo_link", remote: true %>

Now when I click the above link I want to change [1..6] to [1..-1] without rerender in view/users/show:

<section id="photo_galery">
  <% unless @user.photos[0].nil? %>
    <% for photo in @user.photos[1..6] %>
      <%= link_to image_tag(photo.photo.url(:subprofile_thumbnail), id: "subpics"), photo.photo.url(:original), id: "subprofile_photos", class: "fancybox", rel: "gallery01" %>
    <% end %>
  <% end %>
</section>

How can I accomplish this? Thanks!

Jaqx
  • 826
  • 3
  • 14
  • 39

1 Answers1

1

You will have to do the variable change from the controller side.

Controller:

def show
  @user = current_user
  if request.xhr? 
    @photos = @user.photos[1..-1]
  else
    @photos = @user.photos[1..6]
  end 
end

View: show.html.erb

<section id="photo_galery">
  <%= render "photos"%>
</section>
<%= link_to "Photos (#{@user.photos.count})", user_path(@user), id: "photo_link", remote: true %>

_photos.html.erb

<% unless @user.photos[0].nil? %>
    <% for photo in @photos %>
      <%= link_to image_tag(photo.photo.url(:subprofile_thumbnail), id: "subpics"), photo.photo.url(:original), id: "subprofile_photos", class: "fancybox", rel: "gallery01" %>
    <% end %>
  <% end %>

show.js.erb (if using jquery)

  $("#photo_galery").html("<%= escape_javascript(render(:partial => 'users/show', :object => @photos)) %>");

If you are using prototype, you will have to do it in controller.

Srikanth Jeeva
  • 3,005
  • 4
  • 38
  • 58