# Ajax and Rails

**URL:** <https://www.ruby-forum.com/t/ajax-and-rails/106536>\
**Category:** Rails\
**Created:** [June 11, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/ajax-and-rails/106536 "2007-06-11T19:18:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![turnkeytraders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba8739/32.png) [@turnkeytraders](https://www.ruby-forum.com/u/turnkeytraders)\
**Post date:** [June 11, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/ajax-and-rails/106536/1 "2007-06-11T19:18:59Z")

</div>

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:

 Create Client \<%= javascript\_include\_tag :defaults %\>
# New Client

| | |
|
| |
| First Name: | |
| Last Name: | |
| Email: | |
| Gender: | 

```
  <select id="client_gender" name="client[gender]" onChange="<%=

```

remote\_function(  
:url =\> {:action =\> ‘change’}) %\>"\>  
- Select -  
Male  
Female

 |
| 
 Have you been tested for prostate cancer?&nbsp;&nbsp;Yes &nbsp;No 
 |
|
| |
| 
 Have you been tested for breast cancer?&nbsp;&nbsp;Yes &nbsp;No 
 |
|
| |
| Console: | 

```
  <input type="text" id="console_name" name="console[name]"

```

value="\<%= @console.name %\>" /\>  
  
+&nbsp;  
-

```
</td>

```

 |
|   
  
 |

\<%= link\_to 'Back', :action =\> 'list' %\>

And here is my .rjs:

page.insert\_html :before, ‘console\_name’, "   
"

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
