I'm still a newb but having fun - Any help on this problem will be much appreciated. I have mymodel Call.rb
class Call < ActiveRecord::Base belongs_to :user has_many:visits, :dependent => :destroy has_many:visits do def latest find :all, :order => 'id DESC', :limit => 3 end
def all_latest find :all, :order => 'id DESC' end end def self.search(search, page) paginate :per_page => 4, :page => page, :conditions => ['name like ?', "%#{search}%"], :order => 'name' end end
And my controller for CallsController with index action
class CallsController < ApplicationController before_filter :login_required, :only => [ :new, :create, :show, :index, :list, :all_show, :edit, :update, :delete ]
def index
@calls = Call.search(params[:search], params[:page])
end
my view page for index is
<% form_tag calls_path, :method => 'get' do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %>
<% for call in @calls %> <%= link_to h(call.name), :action => 'show', :id => call %> <% end %>
<br />
<%= will_paginate @calls %>
And what happens is that the paginate shows all the calls in the database for all the users but I only want it to paginate the current users calls. I've tried all sorts of things but not sure what to do. any suggestions will be appreciated. if you need more of my code let me know. I used the rails cast and obie Fernandez book and looked on line