Hello, I have been trying to use ajax and rails for a drop down list and I can''t seem to get it to work. This is what I am looking for, I have a drop down list, and as soon as the user selects an option, I want it to dissapear and make my content between the div I specified appear on the form. I have like 3 different divs with different content in them for each drop down item. I have tried to do it with RJS and declaring my own javascript functions but I can''t seem to get it to work. Any help would be appreciated please? Thanks -- 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 Matthew, Matthew Lagace wrote:> I have been trying to use ajax and rails for a drop > down list and I can''t seem to get it to work.What do you mean ''can''t seem to get it to work''? What is it doing / not doing. Where''s the relevant code? We can''t help much without more info. Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Matthew, > > Matthew Lagace wrote: > >> I have been trying to use ajax and rails for a drop >> down list and I can''t seem to get it to work. > > What do you mean ''can''t seem to get it to work''? What is it doing / not > doing. Where''s the relevant code? We can''t help much without more > info. > > BillSorry hehe, well when I click on the item I want, I tried to put an observer on the select id="mediaType", then i wanted to put in my RJS template something like if page[:mediaType][:value] = ''Game'' page.remove ''mediaType'' page.show ''form_game'' end I wanted to do that for all my mediaType items -- 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 -~----------~----~----~----~------~----~------~--~---
Matthew Lagace wrote:> Sorry hehe, well when I click on the item I want, I tried > to put an observer on the select id="mediaType",Is the observer firing? What do you see in Firebug when you click an item?> then i wanted to put in my RJS template something like > if page[:mediaType][:value] = ''Game''What is this? Is this how you''re trying to get the value returned when the user makes a selection? Cause it ain''t the way to do it. Post the relevant code from the view that generates the request, the controller method that gets invoked, and the RJS template. Then we can give you some guidance. Have you worked with RJS before? If not, I highly recommend Cody Fauser''s PDF at O''Reilly: "RJS Templates". It''s $10 you''ll be glad you spent. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Matthew Lagace wrote: > >> Sorry hehe, well when I click on the item I want, I tried >> to put an observer on the select id="mediaType", > > Is the observer firing? What do you see in Firebug when you click an > item? > >> then i wanted to put in my RJS template something like >> if page[:mediaType][:value] = ''Game'' > > What is this? Is this how you''re trying to get the value returned when > the > user makes a selection? Cause it ain''t the way to do it. Post the > relevant > code from the view that generates the request, the controller method > that > gets invoked, and the RJS template. Then we can give you some guidance. > > Have you worked with RJS before? If not, I highly recommend Cody > Fauser''s > PDF at O''Reilly: "RJS Templates". It''s $10 you''ll be glad you spent. > > Best regards, > BillOk here''s my controller code: class ClientController < ApplicationController scaffold :client def change end end my view code: Release Name: <input type="text" id="release_name" name="release[name]" value="<%= @release.name %>" /> Release Type: <select id="mediaType" onChange="<%= link_to_remote ''Change Release'', :url => {:action => ''change''} %>"> <option value="Game">Game</option> <option value="Music">Music</option> <option value="Movie">Movie</option> </select> <div id="game_form"> Genre: <input type="text" id="game_genre" name="game[genre]" value="<% @game.genre %>" /> </div> and I do the same thing for music and movie with different inputs <input type="submit" id="Submit" value="Submit" /> and here is my RJS ''change.rjs'' template code: I was doing something like if page[:mediaType][:value] = ''Music'' page.remove ''mediaType'' page.show ''music_form'' end I did this for game and movie too I would buy the book but I don''t have a credit card :) Thanks -- 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 Matthew, No offense intended, but after seeing your code I think you ought to work through a basic tutorial or two to get your arms around Rails'' basics before you tackle RJS. The cookbook tutorial at O''Reilly that Curt and I did is pretty much up to date. It''s at http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html?page=1 Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Matthew, > > No offense intended, but after seeing your code I think you ought to > work > through a basic tutorial or two to get your arms around Rails'' basics > before > you tackle RJS. The cookbook tutorial at O''Reilly that Curt and I did > is > pretty much up to date. It''s at > http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html?page=1 > > Best regards, > BillI''ve already done that, I already made some exercises with that and they worked fine, its just I''m having trouble in using ajax, I know how to use my models and controllers and to make my custom views its just I want to learn more with ajax. I have already made some examples that I insert data into 2 different tables and databases on the same form thats not my problem. -- 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 -~----------~----~----~----~------~----~------~--~---
Hello, I am working on a form to insert multiple items in different tables here is the code I have: class ClientController < ApplicationController scaffold :client def index if params[:letter] cond = params[:letter] + "%" @letter = params[:letter] @clients = Client.find :all, :conditions => ["firstname like ?" , cond], :order => "firstname ASC" else @clients = Client.find_all @consoles = Console.find_all @latestclients = Client.find :all, :conditions=> "isTested = 1", :order => "dateReg DESC LIMIT 5" @latestconsoles = Console.find :all, :order => "name DESC LIMIT 5" end end def new @client = Client.new @console = Console.new @datetime = DateTime.now end def create @client = Client.new(params[:client]) @console = Console.new(params[:console]) @client.consoles << @console if @client.save flash[:notice] = ''Client saved succesfully!'' redirect_to :action=> ''index'' else render :action => ''new'' end end def change end def addConsole end def delConsole end end And here is my .rhtml: <html> <head> <title>Create Client</title> <%= javascript_include_tag :defaults %> </head> <body> <h1>New Client</h1> <form action="create/<%= @client.id %>" method="POST"> <table> <tr> <td><input type="hidden" id="client_id" name="client[id]" value="<%@client.id %>" /></td> <td><input type="hidden" id="client_dateReg" name="client[dateReg]" value="<%= @datetime %>" /></td> <tr> <tr> <td>First Name:</td> <td><input type="text" id="client_firstname" name="client[firstname]" value="<%= @client.firstname %>" /></td> </tr> <tr> <td>Last Name:</td> <td><input type="text" id="client_lastname" name="client[lastname]" value="<%= @client.lastname %>" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" id="client_email" name="client[email]" value="<%= @client.email %>" /></td> </tr> <tr> <td>Gender:</td> <td> <!-- Male <input type="radio" id="male_gender" name="client[gender]" value="Male" onClick="<%= remote_function( :url => {:action => ''change''}) %>" />Female <input type="radio" id="female_gender" name="client[gender]" value="Female" onClick="<%remote_function( :url => {:action => ''change_female''}) %>" /> --> <select id="client_gender" name="client[gender]" onChange="<%remote_function( :url => {:action => ''change''}) %>"> <option value="">- Select -</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> </td> </tr> <tr> <td> <div id="male_form" style="display: none"> Have you been tested for prostate cancer? Yes <input type="radio" id="client_isTested" name="client[isTested]" value="1" /> No <input type="radio" id="client_isTested" name="client[isTested]" value="0" /> </div> </td> <tr> <tr> <td> <div id="female_form" style="display: none"> Have you been tested for breast cancer? Yes <input type="radio" id="client_isTested" name="client[isTested]" value="1"/> No <input type="radio" id="client_isTested" name="client[isTested]" value="0"/> </div> </td> <tr> <tr> <td valign="top">Console:</td> <td> <input type="text" id="console_name" name="console[name]" value="<%= @console.name %>" /><br/> <button type="button" id="AddConsole" onClick="<%remote_function( :url => {:action => ''addConsole''}) %>">+</button> <button type="button" id="DelConsole" onClick="<%remote_function( :url => {:action => ''delConsole''}) %>">-</button> </td> </tr> <tr> <td colspan="2" align="center"><br/><br/><input type="submit" id="Submit" value="CREATE" /></td> </tr> </table> </form> <%= link_to ''Back'', :action => ''list'' %> </body> </html> And here is my .rjs: page.insert_html :before, ''console_name'', "<input type=''text'' id=''console_name'' name=''console[name]''/> <br/>" What I am trying to do here is that when the client clicks on the "+" button it calls the addConsole.rjs and it adds another input field to add one more console. Now when I create the client, it only adds the first Console input field and not the second into my database. How can I add multiple items of the same objects into the database? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---