Hi all,

I've followed the recipe 
http://cookbook.hobocentral.net/recipes/33-ajax-filtering-on-a-partially-completed
so create a three level dynamic select (Lote -> Calibrerolha ->
Classerolha) and it's working fine with the "new" action but in the
edit action it does not work. Is always shows the error "undefined
method `map' for #<ActiveRecord::Associations::BelongsToAssociation"
whenever I try to access the edit action.
Can anyone please help me?

Here is the code:

Controller:

def new
    hobo_new(Contagem.new(params[:contagem])) do
      hobo_ajax_response if request.xhr?
    end
  end

def edit

    self.this = Contagem.new(params[:contagem]) if params[:contagem]
    hobo_show do
      hobo_ajax_response if request.xhr?
    end

  end


Application.dryml:

<extend tag="form" for="Contagem">
  <old-form merge>
    <field-list: fields="lote, calibrerolha, classerolha">
      <lote-view:>
          <select-one options="&@contagem.lote" blank-
message="(vazio)" limit="1000"/>
      </lote-view:>
      <calibrerolha-view:>
        <do part="calibrerolha-menu">
        <if test="&@contagem.lote">
          <select-one options="&@contagem.lote.calibrerolhas" blank-
message="(vazio)"/>
        </if>
        <else>
          <select disabled><option>Escolha primeiro um lote</option></
select>
        </else>
                </do>
      </calibrerolha-view:>
          <classerolha-view:>
        <do part="classerolha-menu">
        <if test="&@contagem.calibrerolha">
          <select-one options="&@contagem.calibrerolha.classesrolha"
blank-message="(vazio)"/>
        </if>
        <else>
          <select disabled><option>Escolha primeiro um calibre</
option></select>
        </else>
                </do>
      </classerolha-view:>
    </field-list:>
  </old-form>
</extend>

Application.js:

Event.addBehavior({

    "form.contagem select.contagem_lote:change": function(ev) {
        Hobo.ajaxRequest(window.location.href, ['calibrerolha-menu'],
                         { params: Form.serializeElements([this]),
method: 'get',
                           spinnerNextTo: this, message: "Aguarde por
favor..."} )
    },

        "form.contagem select.contagem_calibrerolha:change": function(ev) {
        Hobo.ajaxRequest(window.location.href, ['classerolha-menu'],
                         { params: Form.serializeElements([this]),
method: 'get',
                           spinnerNextTo: this, message: "Aguarde por
favor..."} )
    }

})

environment.rb:

require 'template_environment_patch'

Notes:

- If I remove the following code from application.dryml, the edit page
is showed without any error and the third select box (Classerolha) e
update whenever I change the second select box (Calibrerolha).

<lote-view:>
          <select-one options="&@contagem.lote" blank-
message="(vazio)" limit="1000"/>
</lote-view:>

- I added template_environment_patch.rb (from the recipe) to the lib
folder.

And the stack trace:

undefined method `map' for
#<ActiveRecord::Associations::BelongsToAssociation.....

/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/
associations/association_proxy.rb:217:in `method_missing'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/taglibs/rapid_forms.dryml:
654:in `select_one'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/lib/hobo/dryml/
template_environment.rb:328:in `_tag_context'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/lib/hobo/dryml/
template_environment.rb:248:in `new_context'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/
capture_helper.rb:129:in `with_output_buffer'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/lib/hobo/dryml/
template_environment.rb:248:in `new_context'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/lib/hobo/dryml/
template_environment.rb:328:in `_tag_context'
/Library/Ruby/Gems/1.8/gems/hobo-1.0.1/taglibs/rapid_forms.dryml:
642:in `select_one'
app/views/taglibs/application.dryml:103:in `form__for_contagem'


Thanks!
Best regards,
Hugo

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to