Callum
Callum

Reputation: 38

Unable to get sync gem working, (nomethod error)

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.

Upvotes: 0

Views: 473

Answers (1)

sjain
sjain

Reputation: 23344

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

Upvotes: 0

Related Questions