Closed danil-z closed 13 years ago
I would say that this question is a top candiate for activescaffold group, but anyway a few hints to get you to your goal:
in school model i put following code delegate :region, :to => :city , :allow_nil => true
and in controller active_scaffold :school do |conf| conf.columns = [:title, :region, :city ] end i get column like this in list view
i tried add to region model
class Region < ActiveRecord::Base
has_many :cities, :dependent => :destroy
has_many :schools, :through => :cities
def to_label
"#{name}"
end
end
but it has no affect to view in rails console if run School.find(:first).region.class i get => Region(id: integer, name: string, created_at: datetime, updated_at: datetime)
i tried tons of combinations but have no success on them...
Started GET "/schools" for 127.0.0.1 at 2010-12-29 12:11:16 +0300 ActiveScaffold: Missing date picker localization for your locale: ru ActiveScaffold: Missing datetime picker localization for your locale: ru Processing by SchoolsController#index as HTML SQL (0.3ms) SELECT COUNT() FROM "schools" School Load (0.3ms) SELECT "schools". FROM "schools" ORDER BY "schools"."id" ASC LIMIT 50 OFFSET 0 City Load (0.3ms) SELECT "cities".* FROM "cities" WHERE ("cities"."id" = 1) Region Load (0.3ms) SELECT "regions".* FROM "regions" WHERE ("regions"."id" = 1) Rendered vendor/plugins/active_scaffold/frontends/default/views/_action_group.html.erb (5.2ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb (17.7ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_column_headings.html.erb (5.4ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_messages.html.erb (1.4ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_messages.html.erb (14.6ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb (13.4ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_action_group.html.erb (77.1ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_actions.html.erb (90.1ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_record.html.erb (126.3ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_pagination.html.erb (2.0ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list.html.erb (192.4ms) Rendered vendor/plugins/active_scaffold/frontends/default/views/_list_with_header.html.erb (231.8ms)
Well :region is a virtual column, which means that you have to configure it on your own in your active_scaffold_config. eg if you would like to call to_label on region you have to generate a form column override which actually does that.
to test helper override i've added
module SchoolsHelper
def school_region_column(record)
"1111"
end
end
but it doesn't show 1111 in region column...(regarding API it should be affected in list and show actions)..... why? sorry this stupid questions but i really stuck with them for several days and it drives me crazy...
ok finnaly i find way why it didin't work
def region_column(record)
"1111"
end
it should be named like this main question: which version of api should i review on original activescaffold wiki seems In v2.3 and previous versions format was #{column_name}_column, so method was named username_column
prior 2.3 ?
Yes, without the controller name at the beginning
steal can't handle 2nd question
active_scaffold :school do |conf|
conf.columns = [:title, :region, :city ]
conf.columns[:region].form_ui = :select
conf.columns[:region].update_columns = :city
conf.columns[:city].form_ui = :select
end
i have this in controller atm
Change def region_form_column(record,options) select(:record, :region, Region.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'None'}) end
to def region_form_column(record,options) select(:record, :region, Region.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'None'}, options) end
i got error Started GET "/schools/render_field?column=region&update_columns[]=city&value=2" for 127.0.0.1 at 2010-12-29 16:26:25 +0300 Processing by SchoolsController#renderfield as /_ Parameters: {"column"=>"region", "update_columns"=>["city"], "value"=>"2"} Completed in 7ms
NoMethodError (undefined method `region=' for #<School:0xa1ccba4>):
in model i have delegate :region, :to => :city , :allow_nil => true i'm not sure what i should do ...
i have a copy on github of my application git://github.com/blackbumer/dnevnik.git maybe i have something wrong in other place than model?
Ok, it s getting interesting.
delegate method is just creating a getter method... now you need a setter method, cause current region value has to be stored. so you have to create a setter in your model.
However, you are running now in some trouble, cause delegate is nt working for you anymore. So i think you have to do it on your own and write your own getter.
Maybe something like the following def region @region ||= self.city.try(:region) end
def region=(region) if region.is_a? Region @region = region else @region = Regions.find(region) end end
omg it's finally working! thank you a lot now i need clean my mind and review all code may be i should write some wiki page about such situation? to help others (by simple example )
Great, that would be a good idea.
BTW: If just updated the ru locale file to at least include all new keys. Would be great if you could take a look and add corresponding translation. Thanks a lot.
sure i could add it but how to update your plugin correctly? i've installed as described at your blog howto rails plugin install git://github.com/vhochstein/active_scaffold.git if i just clone it with git command it will rewrite all files? (will reset jquery settings inside enviroment files in plugin folder...) sory for stupid question again i just started with ruby and rails 3 weeks ago... and not familar with git much too :)
1 more little question :
def region_form_column(record,options)
select(record, :region, Region.all.collect {|p| [ p.title, p.id ] }, {:include_blank => t('choose_region')}, options)
end
how to make this helper point selected element (if i update a school witch already have selected city,it should show select input with slected region of city...)
btw your generator active_scaffold_setup for jquery inserts jquery-ui.js and stylesheets but seems my pages don't use it for the scaffold component... may be need to remove frome generator? just a sugesstion...
jquery ui is needed for example for datepicker,... so I do not recommend deleting it.
@select_issue: take a look at def active_scaffold_input_enum in form_column_helpers
@russian locale: best but not easiest way: fork my repository make changes to russian local and send me a pull request. easiest way: change russian locale and upload the file to somewhere I can reach it.
thanks for your help all is clear for me now :)
You are welcome
Hi folks i have 3 simple models class Region < ActiveRecord::Base has_many :cities has_many :schools, :through => :cities end