Hi Guys,
I am trying to get my head around drop down menus and observe_field
(ajax?)
I have :
a ''job'' model
a vfxshotid model
A job has_many :vfxshotids
A vfxshotid belongs_to :job
I need a page that has 2 drop down menus
The first - list of ''vfxshotids'' for a job
The second -  is a list of directories in a ''vfxshotid''
directory.
At the moment I don''t know how to pass the arguements around. I
followed
this post but i can get it to work, and i wonder if the code is out of
date anyway -
http://www.nabble.com/related-drop-down-list---ajax-td2367869.html
If anyone can give me some advice I''d really appreciate it.
Thanks!
Adam
Here is my code:
------------------------------------------------------------
VIEW - newvfxasset.html.erb
------------------------------------------------------------
<% title ''New Asset''%>
<h1>New asset</h1>
<%= error_messages_for :asset %>
<% form_for @asset do |f| %>
  <select name="vfxshotid" id="vfxshotid">
     <option value="">Select VFX shot id</option>
     <% for vfxshot in
(1..-3jiNAoIpU+V6EW1nppFElMeiDAhbh1OB@public.gmane.org) %>
        <option value="<%= vfxshot.object_id %>">
           <%= @job.vfxshotids[vfxshot].jobvfxshot_name %>
        </option>
     <% end %>
  </select>
  <div id="vfxapp_id_container">
    <select id=''vfxapp_id_container''
name=''vfxapp_id_container''>
        <option value=''''>Select VFX app</option>
    </select>
  </div>
  <%= observe_field("vfxshotid", :frequency => 0.25, :update
=>
"vfxapp_id_container", :url => { :action =>
:get_vfxapps_for_vfxshotid
}, :with => "''vfxshotid=''+value") %>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>
<%= link_to ''Back'', assets_path %>
------------------------------------------------------------
jobs controller
------------------------------------------------------------
  def newvfxasset
    def get_vfxapps_for_vfxshotid
        @loggedinuser = session[:user_id]
        @assetstartpath = @@jobsrootdirectory + ''/'' +
@job.jobidstring +
''_'' + @job.client.name + ''/vfx/'' + vfxshotid
+ ''/'' + @loggedinuser.login
        print @assetstartpath
        # @vfxshotidvfxapps = [Dir.glob(@assetstartpath)]
        @vfxshotidvfxpaps = [''a'', ''b'',
''c'', ''d'']
    end
    @job = Job.find(params[:id])
    @asset = Asset.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @job }
    end
  end
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Aug-31  12:54 UTC
Re: newb q: Dynamic Dropdown Menu - Observe field - Ajax
On Aug 31, 1:19 pm, Adam Teale <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi Guys, > > I am trying to get my head around drop down menus and observe_field > (ajax?)Yup observe_field uses ajaz> > At the moment I don''t know how to pass the arguements around. I followed > this post but i can get it to work, and i wonder if the code is out of > date anyway -http://www.nabble.com/related-drop-down-list---ajax-td2367869.html >Well something that will confuse the browser is the fact that you''ve got 2 things on the page with id vfxapp_id_container which can easily have unpredictable consequences. Your get_vfxapps_for_vfxshotid action should be using params[:vfxshotid] since that''s what will get submitted by observe_field. Other than that you haven''t said exactly what is happening/not working so it''s hard to say anything more. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred thanks for replying - I will try to apply what you''ve suggested and post the results, cheers! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Fred,
I think I have made some progress - i think my arguments get passed into 
a function in my controller - but i just can''t seem to get them to 
appear in the 2nd drop down menu - although the menu does seem to 
refresh (but is rendered blank).
Mind taking a look?
Any pointers would be great!
Thanks
Adam
----------
controller
----------
  def get_vfxapps_for_vfxshotid
      @job =  Vfxshotid.find(params[:id]).job
      @loggedinuser_login = User.find(session[:user_id]).login
      puts ''job: '' + @job.jobidstring
      puts ''user: '' + @loggedinuser_login
      @vfxshotid = Vfxshotid.find(params[:id]).jobvfxshot_name
      @assetstartpath = @@jobsrootdirectory + ''/'' +
@job.jobidstring +
''_'' + @job.client.name + ''/vfx'' +
''/'' + @vfxshotid + ''/work/'' +
@loggedinuser_login.to_s
      @vfxshotidvfxapps = Dir.glob(@assetstartpath + "/*/*")
      #see in terminal if directories are found
      puts ''path: '' + @assetstartpath
      for dir in @vfxshotidvfxapps
        puts dir
      end
  end
--------------------
view - newvfxasset.html.erb
--------------------
<% title ''New Asset''%>
<h1>New asset</h1>
<%= error_messages_for :asset %>
<% form_for @asset do |f| %>
  <select name="vfxshotid" id="vfxshotid">
    <%= f.collection_select :job_id, @job.vfxshotids, :id, 
:jobvfxshot_name, :prompt => "Select your VFX Shot ID" %>
  </select>
  <select id="vfxshotidapps" name="vfxshotidapp">
        <option value="">Select your VFX App</option>
  </select>
    <%= observe_field("vfxshotid",
    :url => { :action => "get_vfxapps_for_vfxshotid" },
      :update => "vfxshotidapps",
    :with => "''id='' + value",
    :on => "changed")
    %>
    <%= f.submit "Create" %>
<% end %>
<%= link_to ''Back'', assets_path %>
--------------------
view - get_vfxapps_for_vfxshotid.html.erb
--------------------
<% for dir in @vfxshotidvfxapps %>
    <option value="<%= dir %>"><%= dir
%></option>
<% end %>
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
haha! success! the controller''s function seemed to be outputting with a layout - ???? i read that to disable a rendered layout u just need to append the following to a function: render :layout => false sweet! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---