Topic: sort content and refesh it on the same page?

I'm really new to Ruby On Rails and have a big problem by finding a solution to refresh a page with another sorting.First it's sorted next to names, after a button-press, it should sort the content next to the rating.It shows the correct solution in the adress window of the browser (just like: http://localhost:3000/?[]=2&[]=3&[]=9&[]=5&[]=6&[]=1&[]=7&[]=8&[]=4), but do not update the page...Would be great if someone can help me!!!

Last edited by weserwurst (2012-05-23 18:10:25)

Re: sort content and refesh it on the same page?

and some code for the problem...
---
store_controller.rb
----
class StoreController < ApplicationController
  def index
    @brands = Brand.find(:all, :order => "name")
    sort_rating
  end

  private

  def sort_rating
    @brands_rating_sortieren = Brand.find(:all, :order => "rating DESC")
    render 'ore/index'
  end
end

---
index.html.erb
---
<%= link_to 'absteigend nach Rating sortieren', store_path( @brands_rating_sortieren)%>

Re: sort content and refesh it on the same page?

The easiest and straightforward way is to make order dependent on index parameter. Like this:

  def index
    sort_by = params[:sort_by] || 'name'
    @brands = Brand.find(:all, :order => sort_by)
  end

For this you will need put this parameter to sorting link:

<%= link_to 'Name', stores_path(:sort_by => 'name') %>

PS: Please, do naming of your variables in english.

Re: sort content and refesh it on the same page?

Wow... thanks a lot for your help!!!!
I was sitting hours on this two lines of code...
But now everything is working!