Sometimes I need a set a few form columns to a certain value based on where
the form is invoked in the application (if nested, if with associations,
etc.), otherwise the form colums should function as normal(if no conditions
exist) as send_form_on_update_column. I'm having trouble doing both.
I need advice on writing the helper cleanly.
Example:
Model: widget.rb
belongs_to :rtype
belongs_to :widgettype
belongs_to :widgetmodel
Controller: widget_controller.rb
active_scaffold :"widget" do |conf|
…
conf.columns[:rtype].label = "Entity"
conf.columns[:rtype].form_ui = :select #example: “Software”
conf.columns[:rtype].update_columns = :widgettype
conf.columns[:rtype].send_form_on_update_column = true
…
conf.columns[:widgettype].label = "Type"
conf.columns[widgettype].form_ui = :select #example: “Audio Editing Suites”
conf.columns[widgettype].update_columns = [:widgetmodel]
conf.columns[widgettype].send_form_on_update_column = true
…
conf.columns[:widgetmodel].label = "Model"
conf.columns[:widgetmodel].form_ui = :select #example: “Audacity 2.1.0”
\\widget_helper.rb
…
def rtype_form_column(record, options)
columns = [ 'name', 'id'] # Rtype's name for the selection box.
list = Rtype.find :all,
:select => columns.join(', '),
:order => 'name'
@rtypes = list.map{|r|[r.name, r.id]}
if params[:widgetmodel_id] #Form invoked from WidgetModel list. (create new
from nested view)
widgetmodel = Widjetmodel.find(params[:widgetmodel_id])
select(:record, :rtype, @rtypes, :selected =>
assetmodel.rtype_id,:include_blank => true)
elsif @record.rtype #Form invoked where record.rtype is already
assigned.(an update)
select(:record, :rtype, @rtypes, :selected =>
@record.rtype_id,:include_blank => true)
else #If no conditions exist.(create new)
#Behave normally...Forget this form_helper exists.
*#What goes here?*
end
end
--Likewise
def widgettype_form_column(record, options)
columns = [ 'name', 'id'] # add the rest you need
here
list = Widgettype.find :all,
:select => columns.join(', '),
:order => 'name' # maybe some sql to limit it here -
not sure
@widgettypes = list.map{|r|[r.name, r.id]}
if params[:widgetmodel_id] #Form invoked from WidgetModel list. (nested
view)
widgetmodel = widgetmodel.find(params[:widgetmodel_id])
select(:record, :widgettype, @widgettypes, :selected =>
widgetmodel.widgettype_id,:include_blank => true)
elsif @record.widgettype #Form invoked where record.widgettype already
exist (an update)
select(:record, :widgettype, @widgettypes, :selected =>
@record.widgettype_id,:include_blank => true)
else #Forget this form_helper exists.
* #What goes here?*
end
end
Any thoughts would be greatly appreciated!
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/activescaffold.
For more options, visit https://groups.google.com/d/optout.