In my annonce_controller :
helper_method :sort_column, :sort_direction
def index
@annonces = Annonce.order(sort_column + " " + sort_direction)
@modeles = Modele.all
@marques = Marque.order(sort_column + " " + sort_direction)
@energies = Energy.all
end
…
…
private
def sort_column
Annonce.column_names.include?(params[:sort]) ? params[:sort] :
“marque_id”
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] :
“asc”
end
end
For the " def index " I tried :
@annonces = Annonce.order(sort_column + " " + sort_direction)
@marques = Marque.all
and
@annonces = Annonce.find(params[:id])
@marques = Marque.order(sort_column + " " + sort_direction)
In my marque_controller :
class MarquesController < ApplicationController
helper_method :sort_column, :sort_direction
def index
@marques = Marque.order(sort_column + " " + sort_direction)
end
…
…
private
def sort_column
Marque.column_names.include?(params[:sort]) ? params[:sort] :
“marque”
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] :
“asc”
end
end
the annonce.rb model :
class Annonce < ActiveRecord::Base
attr_accessible :marque_id, :modele_id, :price, :type, :energy_id,
:power
belongs_to :marque
belongs_to :modele
belongs_to :energy
end
the marque.rb model :
class Marque < ActiveRecord::Base
attr_accessible :marque
has_many :modeles
has_many :annonces
end
The view : annonce : index.html.erb
<%= sortable "marque_id" %> |
<%= sortable "modele_id" %> |
<%= sortable "price" %> |
<%= sortable "power" %> |
<%= link_to "Energy", :sort => "energy_id" %> |
<% for annonce in @annonces %>
<%= annonce.marque.marque %> |
<%= annonce.modele.try(:modele) %> |
<%= annonce.price %> € |
<%= annonce.power %> |
<%= annonce.energy.try(:energy) %> |
<% end %>
The view of marque look like this.
My tables looks like that :
Annonces:
create_table :annonces do |t|
t.integer :marque_id
t.integer :modele_id
t.string :price
t.string :power
t.string :energy
Marque:
create_table :marques do |t|
t.string :marque
t.timestamps
I hope this will help…
I’d create all this by doing : rails g scaffold marque marque:string
Or : rails g scaffold annonce marque_id:integer […]
Thank you again 
++++