SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    partials and AJAX

    Hello I have (in add_article.rhtml) a select field with some option that shows a partial in according to the selected value (though observe_fied)

    Code Ruby:
    <%= select_tag :article_type, options_for_select(Article::ARTICLE_TYPES) %>
    <%= observe_field	:article_type,
    				  :update => :articleForm,
    				  :url => { :action => :show_article_form }, 
    			          :with => "article_type" %>
    <% end %>

    and it works fine. The problem is that in the partials I need some instance variable to populate some other select, for instance:

    Code Ruby:
    <%= form.select :unit_id, @unit_list %>

    but even if I have in my controller

    Code Ruby:
    def add_article
        @unit_list = Unit.find(:all, :conditions => "scope = 1", :order =>"name").map { |u| [u.name, u.id] }
      end

    I have a nill error

    You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.inject

    related to the select above.

    If I put directly the partial on add_article.rhtml it works do I guess the issue is related to the ajax call.

    In which way can I use @unit_list in a partial that is called though ajax ???

    THANKS
    Alla prossima ...

  2. #2
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nobody
    Alla prossima ...

  3. #3
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't work because you're setting the instance variable in the wrong request. You should set it in the action that is called via Ajax, not the action that generates the observe_field.

  4. #4
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Buddy.
    I appreciate it ( as always )

    Have a good 1 !!
    Alla prossima ...

  5. #5
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I have the values on the selects but I can not open them, I mean if I click over the arrow to expand them nothing happens.

    But If I render directly the partial on my page everything works fine.

    Can be related to the ajax call ?????





    THANKS
    Alla prossima ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •