El Thursday 23 April 2009 21:52:51 Jan escribió:
> Hi,
>
> I am wondering how get I get other values betwen models. Lets say I
> have this two model:
>
> class People < ActiveRecord::Base
> belongs_to :place, :foreign_key => :id, :class_name =>'People'
> end
>
> class Place < ActiveRecord::Base
> has_many :peoples
> end
>
> class PeoplesController < ApplicationController
> layout "peoples"
> active_scaffold :people do |config|
> config.label = "Them"
> config.columns = [:name, :last_name, :place]
> list.columns.exclude :poznamka, :rodne_meno, :place
> list.sorting = {:priezvisko => "ASC"}
> #config.actions.exclude :create, :delete,
> #columns[:name].label = "Name"
> columns[:place].label = "Street"
> config.nested.add_link "Hrobové miesto", [:place]
> end
> end
>
> This works fine, but I would like to display some fields from place
> model directly in listing, not model as a link only.
>
> For example I display list of people and I want to display street,
> postcode..etc from place model.
>
> Thank you for your suggestions.
You can define to_label for Place model, it will be used for update header
too, like Update <result of place.to_label>
You can define a helper for your place column and get the values:
def place_column(record)
"#{record.street} (#{record.postcode})"
end
If you want to show some fileds from an association in different columns, add
virtual columns to your controller (don't forget to exclude from create and
update columns):
active_scaffold :people do |config|
config.columns << [:place_street, :place_postcode]
[...]
end
Then, add methods to get place_street, place_postcode and so on:
class People < ActiveRecord::Base
def place_street
place.try(:street)
end
def place_postcode
place.try(:postcode)
end
end
--
Sergio Cambra .:: entreCables S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---