Hi group,

My environment: gem 'rails', '4.1.6', gem 'active_scaffold',github: 
'activescaffold/active_scaffold', torquebox 3.1.1 (jruby with jboss), gem 
'activerecord-jdbcpostgresql-adapter', gem 'therubyrhino', gem 
'jquery-rails', and others gems, Windows 7 too.

I want to develop a one single page web. Therefore researching and from 
various sources I have made these pieces of code based on jquery and others:

In application_helper:

  def jq_select()
    fntn = <<CMD
    <script>
      $("select[data-target]").change(function(e){
        var curObj = jQuery(this).closest("select");
        var href = curObj.data("href");
        if (href) {
          var destObj = jQuery(curObj.data("target"));
          if (destObj) {
            destObj.addClass('cl_loader');
            destObj.load(href,{id: 
curObj.val()},function(responseTxt,statusTxt,xhr){
              if(statusTxt=="success") {
                destObj.removeClass('cl_loader');
              };
              //if(statusTxt=="error")
              //  alert("Error: "+xhr.status+": "+xhr.statusText);
            });
            destObj.removeClass('cl_loader');
          };
        };
        e.preventDefault();
      });
    </script>
CMD
    fntn.html_safe()
  end

  def jq_form()
    fntn = <<CMD
    <script src="/assets/jquery.serializejson.min.js"></script>
    <script>
      $("form[data-target]").submit(function(e){
        e.preventDefault();
        var curObj = jQuery(this).closest("form");
        var opciones = curObj.serializeJSON({checkboxUncheckedValue: 
"false"});
        //alert(opciones);
        var url = curObj.attr("action");
        cl_state_form(curObj,false);

        if (url) {
          var destObj = jQuery(curObj.data("target"));
          if (destObj) {
            destObj.addClass('cl_loader');
            destObj.load(url+"?" + 
$.param(opciones),function(responseTxt,statusTxt,xhr){
              if(statusTxt=="success") {
                destObj.removeClass('cl_loader');
              };
              if(statusTxt=="error")
                cl_state_form(curObj,true);
            });
            destObj.removeClass('cl_loader');
          };
        };
        cl_state_form(curObj,true);
        return true;
      });
    //------------------
      function cl_state_form(cl_form,state) {
        if (state) {
          jQuery('input[type=submit]', cl_form).removeAttr('disabled');
          jQuery("input,select,textarea", cl_form).removeAttr('disabled');
        } else {
          jQuery('input[type=submit]', cl_form).attr('disabled', 
'disabled');
          jQuery("input,select,textarea", cl_form).attr('disabled', 
'disabled');
        }
      }
    </script>
CMD
    fntn.html_safe()
  end
--------------------------------

In the _subitem.html.haml helper, i use bootstrap and this es part of menu 
generator(This works without problem):
- if current_user and current_user.has_acces(subitem)
  = menu_item(subitem.label, subitem.url,{data: {target: 
'#main-container'}})
-------------------------------------------
in application.html.haml layout (piece):
    =render partial: "layouts/menuboots"
    .container-fluid
      .row
        .col-lg-9
          = bootstrap_flash
          #main-container
            = yield
        .col-lg-3
          .well.sidebar-nav#side-container
-----------------------------------------
in application_controller.rb:

layout proc{ |c| c.request.xhr? ? false : "application" }

---------------------------------------
in the business controller:
  def lst_materias
    im(params)  #only log a message with params...
    im(@ano.ano) #only log a message with params...
    if !params[:id].blank?
      sql = <<QUERYCMD
        select distinct on (ma.area_id,ma.descrip,ma.tipo_mat) 
ma.id,ma.descrip,ma.tipo_mat
          from materias ma inner join materia_anhos man on (ma.id = 
man.materia_id)
            inner join anos an on (man.ano_id = an.id and an.ano = 
'#{@ano.ano}')
            inner join cursos cu on (cu.ano_id=an.id)
            inner join curso_materias cm on (man.id = cm.materia_ano_id and 
cm.curso_id=cu.id)
            inner join grados gr on (cu.grado_id=gr.id)
          where gr.id=#{params[:id]}
        union
        (
        select ma.id,ma.descrip,ma.tipo_mat from materias ma inner join 
materia_anhos man on (ma.id = man.materia_id)
            inner join anos an on (man.ano_id = an.id and an.ano = 
'#{@ano.ano}')
            inner join materia_espec_anos mea on (mea.id = man.id)
            inner join grados gr on (mea.nivel_id = gr.nivel_id)
          where gr.id=#{params[:id]}
        )
        order by id
QUERYCMD
      @result = ActiveRecord::Base.connection.execute(sql)
      im(@result)
      @vvalpos = []
      @result.each {|ele| @vvalpos << [ ele["descrip"].to_s , 
ele["id"].to_s ]}
      im(@vvalpos)
    end
  end

  def index
    im("parametros index:"+params)
    super
  end

  def lista
    im(params)
    @materia_id = params[:materia] rescue ""
    @grado_id = params[:grado] rescue ""
  end
  
  def sel_grado_mater
  end
-----------------------------------------------

in view of business controller:
-- sel_grado_mater.html.haml
= panel nil,{title: "Selección el grado y la materia"} do
  = form_for :competencias, url: "competencias/lista",data: {target: 
"#contenido"},method: "get" do |f|
    = f.label 'Grado:'
    = f.select_tag :grado, 
options_from_collection_for_select(Grado.all.order(["nivel_id","id"]), 
"id", "descrip"), {class: 'form-control', data: {href: 
"competencias/lst_materias",target: "#sel_mater"}}
    = f.label 'Materia:'
    = f.select_tag :materia, [], class: 'form-control', id: "sel_mater"
    = f.submit 'Seleccione', :class => 'button right'
#contenido
= jq_select()
= jq_form()

--- lista.html.haml
- if @materia_id.blank?
  %h1 Por favor seleccione una materia
- elsif @grado_id.blank?
  %h1 Por favor seleccione un Grado
- else
  = render :active_scaffold => "competencias", :constraints => 
{:materia_id=> @materia_id, :grado_id=> @grado_id}
--- lst_materias.html.haml
= options_for_select(@vvalpos)
--- in sel_grado_mater.html.haml
= panel nil,{title: "Selección el grado y la materia"} do
  = form_for :competencias, url: "competencias/lista",data: {target: 
"#contenido"},method: "get" do |f|
    = f.label 'Grado:'
    = f.select_tag :grado, 
options_from_collection_for_select(Grado.all.order(["nivel_id","id"]), 
"id", "descrip"), {class: 'form-control', data: {href: 
"competencias/lst_materias",target: "#sel_mater"}}
    = f.label 'Materia:'
    = f.select_tag :materia, [], class: 'form-control', id: "sel_mater"
    = f.submit 'Seleccione', :class => 'button right'
#contenido
= jq_select()
= jq_form()
--------------------------------------------

This work very simple: with menu select trigger one ajax's action that 
replace the #main-container div.
Here show a form that select grade and this option select fills a option 
select with school subjects.
When click over submit button, trigger one ajax that replace #contenido div 
with a embedded active scaffold controller (competencias), but this shows 
nothing.

Log here:
*************************************
{"utf8"=>"?", "grado"=>"21", "materia"=>"68", "controller"=>"competencias", 
"action"=>"lista"}
*************************************
  Rendered C:/proyectos/rectorware5/app/views/competencias/lista.html.haml 
(1037.0ms)
Completed 200 OK in 1106ms (Views: 1043.0ms | ActiveRecord: 32.0ms)

The render: :active_scaffold => "competencias", :constraints => 
{:materia_id=> @materia_id, :grado_id=> @grado_id} don't work with ajax 
call, and i have reviewed the source code to locate the reason, and I could 
not. I need your help to resolve the impasse, please.

-- 
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.

Reply via email to