extjs - Netzke Has many relation and rails fields_for -
i have simple has_many
relation can implemented rails fields_for
. looking same behavior netzke
.
here classes:
class question < activerecord::base attr_accessible :description, :title validates_presence_of :title, :description has_many :question_options accepts_nested_attributes_for :question_options
end
class questionoption < activerecord::base attr_accessible :title, :question validates_presence_of :title belongs_to :question
end
here form building:
class questionform < netzke::basepack::form js_configure |c| c.mixin end def configure(c) super record.build_for_editing if record.present? c.model = 'question' c.title = 'question' c.items = [:title, :description] end end
upto point form working fine. can't figure out way implement has_many behavior in rails fields_for
can 1 guide me how use netzke
scenario.
are trying implement master-detail/one-to-many editing? if so, example given in netzke demo application (see bosses , clerks in http://netzke-demo.herokuapp.com/).
you need create 3 components:
- question component (master) inheriting netzke::basepack::grid
- questionoption component (details) inheriting from
- netzke::basepack::grid composite component combining previous two
components , adding javascript sync them.
first, questionoption model must allow access id of master table (netzke thing, without not work).
class questionoption < activerecord::base attr_accessible :title, :question_id validates_presence_of :title belongs_to :question end
this components code:
class questions < netzke::basepack::grid def configure(c) super c.model = 'question' c.items = [ :description, :title ] end end class questionoptions < netzke::basepack::grid def configure(c) super c.strong_default_attrs = {question_id: c.question_id} c.scope = {question_id: c.question_id} c.model = 'questionoption' c.columns = [ { name: :title, header: 'option title'} ] end end class questionsandoptions < netzke::base def configure(c) super c.items = [:questions, :question_options] end js_configure |c| c.layout = :border c.border = false c.height = '100%' c.init_component = <<-js function() { this.callparent(); var questions = this.netzkegetcomponent('questions'); var question_options = this.netzkegetcomponent('question_options'); questions.on('itemclick', function(view, record) { this.selectquestion(record.get('id')); question_options.getstore().load(); }, this); } js end endpoint :select_question |id, this| component_session[:selected_question_id] = id end component :questions |c| c.region = :center end component :question_options |c| c.region = :south c.question_id = component_session[:selected_question_id] c.height = '50%' end end
please try , let me know if need. sorry if misunderstood question.
regards
drazen
Comments
Post a Comment