4 Replies - 3910 Views - Last Post: 01 July 2012 - 11:42 AM Rate Topic: -----

#1 1091100582  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 15-August 09

Ajax Dynamic Menu Ruby on Rails

Posted 30 June 2012 - 08:50 AM

I'm implementing a category and subcategory. However, it is using only 1 model with the gem 'awesome_nested_set', so when I click my first collection_Select, it will process my Ajax and return an instant variable for my controller and get the category for the second collection select. I'm almost done, but I still have a little problem.

When I load the page, it gives me an error: "might expect an instance of array". I know why this happens, it's because when I load the page, it actually loads the js, but initially, I haven't clicked the first collection_select. I can't get the value from the select and my controller cannot get the params from there too.

I did try to not run the partial, but my Firebug console shows me red color, but I see it can get the params from the first collection_select.

Here is my gist.gihub

https://gist.github.com/2995276

The full code is provided, please guide me, I need some modifications...

This post has been edited by 1091100582: 30 June 2012 - 06:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Ajax Dynamic Menu Ruby on Rails

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2144
  • View blog
  • Posts: 3,295
  • Joined: 21-June 11

Re: Ajax Dynamic Menu Ruby on Rails

Posted 30 June 2012 - 09:44 AM

View Post1091100582, on 30 June 2012 - 05:50 PM, said:

Here is my gist.gihub

The full code is provided


Where?
Was This Post Helpful? 0
  • +
  • -

#3 1091100582  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 15-August 09

Re: Ajax Dynamic Menu Ruby on Rails

Posted 30 June 2012 - 06:29 PM

argh ,sorry @@ ...https://gist.github.com/2995276
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2144
  • View blog
  • Posts: 3,295
  • Joined: 21-June 11

Re: Ajax Dynamic Menu Ruby on Rails

Posted 01 July 2012 - 02:17 AM

If I understand your code correctly, there's no reason for _category.html.erb to be rendered until a category has been selected (and in fact it shouldn't be because that's causing your error). So unless I'm missing something, why not just remove the call to render from _form.html.erb?

Edit: And replace it with an empty category_select div, so your AJAX code knows what to replace.

This post has been edited by sepp2k: 01 July 2012 - 02:18 AM

Was This Post Helpful? 0
  • +
  • -

#5 1091100582  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 15-August 09

Re: Ajax Dynamic Menu Ruby on Rails

Posted 01 July 2012 - 11:42 AM

thanks for reply, hmm, right now i changed to a empty div, however, actually when i use firebug debug, it able to GET the ajax request, but it show me red color message, it seems that my controller did not respond javascript and render the _category.

oh yah,my console actually showing this error
ActionView::Template::Error (undefined local variable or method `f' for #<#<Class:0x007f1c040722c8>:0x007f1c04046998>):
1: $('category_select').replaceWith('<%= escape_javascript(render :partial => 'category', :locals => { :f => f, :categoryID => @subcategory}) %>')
app/views/javascripts/dynamic_subcategory.js.erb:1:in `_app_views_javascripts_dynamic_subcategory_js_erb__1942042791612699731_69879151602540_988346200319335921'
app/controllers/javascripts_controller.rb:7:in `dynamic_subcategory'


it did go to my dynamic_subcategory.js.erb, but i did pass locals f, it still gave me the error undefine local variable @@

This post has been edited by 1091100582: 01 July 2012 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1