0

I've been trying to install and use the new sync realtime partials gem, but when it comes to putting the code in my views it all goes wrong.

This is my existing code, pre sync.

<%= render :partial => "tasks/table", :locals => { :assigned_to => true, :user_dashboard => false } %>

It now reads:

<%= sync partial: 'task_table', resource: @tasks %>

I've created a sync folder in my views, and a tasks folder, and added in _task_table.html.erb.

NoMethodError in Tasks#index

Showing /Users/callum/rails_projects/arc_app/app/views/tasks/index.html.erb where line #17 >raised:

undefined method model_name for WillPaginate::Collection:Class

In my tasks_controller.rb i have

def index

@tasks = Task.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 15, :page => > params[:page]).find_by_status(params[:status])

end

I'm quite new to rails but, I'm guessing its to do with the @tasks in my controller, I also process the table partial from a different controller with the same / similar error.

Community
  • 1
  • 1
Callum
  • 38
  • 3

1 Answers1

0

Use the following way and don't mix up all together:

def index
user_task = case params[:status].present?
when true then Task.where(:status => params[:status]).all
else Task
end

@tasks = user_task.paginate(:per_page => 15, :page => params[:page]).search(params[:search])
end
sjain
  • 23,126
  • 28
  • 107
  • 185
  • The coding there is a little advanced for my efforts, but I've put it in and now the error has changed to this - undefined method `model_name' for ActiveRecord::Relation:Class – Callum May 01 '13 at 13:23
  • You should have model `Task` in your models folder. For example: `class Task < ActiveRecord::Base end` – sjain May 01 '13 at 13:28
  • See the update. The `Task.find_by_status` will return you the record and not the relation and that's what you want. – sjain May 01 '13 at 13:39
  • Hmm, I must be doing something wrong it seems. Still got the same Relation:Class error. Here are screenshots of my [task index](http://callumbarratt.co.uk/taskindex.jpg) and [controller](http://callumbarratt.co.uk/taskcontroller.jpg). Appreciate the help btw, completely stuck! – Callum May 01 '13 at 13:46
  • Your code works fine if i revert back to my original render partial: line, hmm. – Callum May 01 '13 at 13:53
  • yes that you should keep offcourse. If problem resolved, then don't forget to mark this as an answer :) – sjain May 01 '13 at 13:59
  • It cleaned up my code somewhat, but unfortunately it doesn't resolve the issue of me using the sync gem :( As I said, I had to revert back to rendering the partial normally, which doesn't give me the gem functionality! – Callum May 01 '13 at 14:02
  • Check this update again. May be this is what you want. I don't know about the sync gem but the above code is correct as far as I know. – sjain May 01 '13 at 14:08