Module: RulesEngineView::ModelLoader
- Defined in:
- lib/rules_engine_view/model_loader.rb
Instance Method Summary collapse
-
#re_load_model(model_name, options = {}) ⇒ Object
options => :parents array of required parent objects => :param_id (default = id) => :find_by (default = find) => :redirect_path.
Instance Method Details
#re_load_model(model_name, options = {}) ⇒ Object
options
> :parents array of required parent objects
> :param_id (default = id)
> :find_by (default = find)
> :redirect_path
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rules_engine_view/model_loader.rb', line 8 def re_load_model(model_name, = {}) model = re_find_model(model_name, ) parent = [:parents] == nil ? nil : [:parents].last if (model != nil && parent != nil) parent_param = [:parent_param] ? [:parent_param] : "#{parent}_id" model = nil if (instance_variable_get("@#{parent}") == nil || (instance_variable_get("@#{parent}").id != model.send(parent_param))) end instance_variable_set("@#{model_name}", model) if model == nil flash[:error] = "Unable to load #{model_name.to_s.camelcase}." redirect_path = model_index_path(model_name, ) respond_to do |format| format.html { redirect_to(redirect_path) } format.js { render :update do |page| page << "window.location.href = '#{redirect_path}';" end } end end end |