开发者

Why wont jQueryUI buttons and javascript work when I'm using will_paginate?

开发者 https://www.devze.com 2023-03-14 02:22 出处:网络
In my app I\'m filtering through venue records using javascript and displaying them in partials on the venue index page. However, the filter form breaks when I have will_paginate set up, they both wor

In my app I'm filtering through venue records using javascript and displaying them in partials on the venue index page. However, the filter form breaks when I have will_paginate set up, they both work individually but not together. What am I doing wrong here?

jQuery script

<script>
  $(function() {
    $(".venuetypes").buttonset();
  });

  $(function() {
    $(".areas").buttonset();
  });

  $(function() {
    $( "button, input:submit, a", ".filter_form_button" ).button();
    $( "a", ".form_filter_button" ).click(function() { return false; });
  });
</script> 

filter form

<div class="filter_options_container">
  <%= form_tag '', :method => :get, :id => 'filter_form' do %>

    <fieldset class="filter_form_fieldset venuetypes">
      <% Venuetype.all.each do |v| %>
        <p class="venuetype_check"><%= check_box_tag 'venuetypes[]', v.id, false, :id => "venuetype-#{v.id}" %>
        <label for="venuetype-<%= v.id %>"><%= v.name %></label></p>
      <% end %>
    </fieldset>

    <fieldset class="filter_form_fieldset areas">
      <% Area.all.each do |a| %>
        <p class="area_check"><%= check_box_tag 'areas[]', a.id, false, :id => "area-#{a.id}" %>
        <label for="area-<%= a.id %>"><p1><%= a.name %></p1></label></p>
      <% end %>
    </fieldset>

    <div class="filter_form_button">
      <p2><input type="submit" value="Filter"/></p2>
开发者_运维问答    </div>
  <% end %>
</div>

venue controller

  def index
    if
      @venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
    else
      @venues = Venue.all
    end
    @venues = Venue.paginate :all, :page => params[:page], :per_page => 15
  end

Thanks very much for any help its much appreciated!


You are overwriting the @venues variable, when I think you are trying to add pagination to that query. Try this instead:

def index
  if
    @venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
  else
    @venues = Venue.all
  end
  @venues = @venues.paginate :per_page => 15, :page => params[:page]
end


You are adding an extra comma.

This is how it should be:

Model.pagination :per_page => 15, :page => params[:page]

So you should have this:

def index
  if
    @venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
  else
    @venues = Venue.all
  end
  @venues = Venue.paginate :per_page => 15, :page => params[:page]
end
0

精彩评论

暂无评论...
验证码 换一张
取 消