I have two tables with a has_and_belongs_to_many relationship, Project and Category.
I list out all my Project records on my views/projects/new.html.erb like this:
<% @projects.each do |project| %>
<tr class="project <% project.categories.all.each do |cat| %><%= cat.name %> <% end %>">
<td><a href='project/<%= project.id %>'><%= project.filename %></a></td>
<td><%= project.author %>
<td><% project.categories.all.each do |cat| %><%= cat.name %>, <% end %></td>
</tr>
<% end %>
And have defined several link_to remote links like this:
<div class="filterBy">SORT BY:</div>
<div class="filterBy"><%= link_to "Category", :update => "projects", :url => { :action => "sortTable", :filter => "Category" }, :remote => true %></div>
<div class="filterBy"><%= link_to "Author", :update => "projects", :url => { :action => "sortTable", :filter => "Author" }, :remote => true %></div>
<div class="filterBy"><%= link_to "Date", :update => "projects", :url => { :action => "sortTable", :filter => "Date" }, :remote => true %></div>
And in my projects_controller I have
def sortTable
@projects = Project.find(:all, :order => params[:filter])
end
When I click the links though, nothing happens. What am I doing wrong? I want it to update without refreshing the page as well. If need be, my routes.rb looks like
Docside::Application.routes.draw do
resources :projects
resources :categories
#get "home/index"
root :to => "projects#new"
match 'project/new',:controller=>"projects",:action=>"create"
match "project/:id", :controller => "projects", :action=>"download"
end