# Partials problem

**URL:** <https://www.ruby-forum.com/t/partials-problem/109012>\
**Category:** Rails\
**Created:** [July 10, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/partials-problem/109012 "2007-07-10T17:11:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 10, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/partials-problem/109012/1 "2007-07-10T17:11:25Z")

</div>

I’ve been working with a tutorial over on [railsforum.com](http://railsforum.com) on creating  
variable numbers of models in one form.

I have a script model that has one or many script\_metadatas.

My code is the following:

1. 
# scripts\_controller.rb
2. def new
3. 

```
@script = Script.new

```

4. 

```
@script.script_metadatas.build

```

5. end
6. 
7. def create3
8. 

```
@script = Script.new(params[:script])

```

9. 

```
params[:script_metadatas].each_value { |script_metadata|

```

@script.script\_metadatas.build(script\_metadata) }  
10. if @script.save  
11. redirect\_to :action =\> ‘index’  
12. else  
13. render :action =\> ‘new’  
14. end  
15. end  
16.  
17. def add\_script\_metadata  
18. @script\_metadata = Script\_metadata.new  
19. end  
20.  
21. # scripts/new.rhtml  
22. \<% form\_for :script, :url =\> { :action =\> ‘create3’ } do |f| %\>  
23.

Description: \<%= f.text\_field :description %\>

  
24. 
## Script\_metadatas
  
25. 
  
26. \<% @script.script\_metadatas.each\_with\_index do |script\_metadata,  
index| %\>  
27. \<%= render :partial =\> ‘script\_metadata\_fields’, :locals =\> {  
:script\_metadata =\> script\_metadata, :index =\> index } %\>  
28. \<% end %\>  
29. 
  
30. \<%= render :partial =\> ‘add\_script\_metadata\_link’, :locals =\> {  
:index =\> @script.script\_metadatas.size } %\>  
31. 

\<%= submit\_tag ‘Create Script’ %\>

  
32. \<% end %\>  
33.  
34. #scripts/\_script\_metadata\_fields.rhtml  
35. 
  
36. \<% fields\_for “script\_metadatas[#{index}]”, script\_metadata do |f|  
%\>  
37. 

38. \<%= f.text\_field :meta\_key %\>  
39. \<%= link\_to\_remote ‘remove’, :url =\> { :action =\>  
‘remove\_script\_metadata’, :index =\> index } %\>  
40.

  
41. \<% end %\>  
42. 
  
43.  
44. # scripts/\_add\_script\_metadata.rjs  
45. 
  
46. \<%= link\_to\_remote ‘Add Another Script\_metadata’, :url =\> {  
:action =\> ‘add\_script\_metadata’, :index =\> index } %\>  
47. 
  
48.  
49. # scripts/add\_script\_metadata.rjs  
50. page.insert\_html :bottom, :script\_metadatas, :partial =\>  
‘script\_metadata\_fields’,  
51. :locals =\> { :script\_metadata =\> @script\_metadata, :index =\>  
params[:index] }  
52.  
53. page.replace :add\_script\_metadata\_link, :partial =\>  
‘add\_script\_metadata\_link’, :locals =\> { :index =\> (params[:index].to\_i

- 
  1. }

  1. 
  2. 
# scripts/remove\_script\_metadata.rjs
  3. page[“script\_metadata\_#{params[:index]}”].remove

The problem being, when I click on the button that calls  
‘add\_script\_metadata.rjs’ nothing happens and I don’t get another row to  
input another set of metadata.

Can anyone suggest why this is?

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 10, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/partials-problem/109012/2 "2007-07-10T17:21:03Z")

</div>

Howdy Paul,

On 10-Jul-07, at 11:11 AM, Paul Noga wrote:

> 1. 
> 
> ```
> @script = Script.new
> 
> ```
> 
> 2. 
> 
> ```
> @script.script_metadatas.build
> 
> ```
> 
> 3. end
> 4.

> The problem being, when I click on the button that calls  
> ‘add\_script\_metadata.rjs’ nothing happens and I don’t get another  
> row to  
> input another set of metadata.
> 
> Can anyone suggest why this is?

This is the kinda problem where the right debugging tool will pay  
huge dividends.

(if you haven’t) pickup firebug[1] - using it you can watch the http  
request/response; then tail your development log. These 2 bits of  
info will tell you more symptoms. You’ll likely solve your problem,  
if not you’ll have more info for us to help you out.

Jodi

[1] [http://www.getfirebug.com/](http://www.getfirebug.com/)

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 11, 2007, 11:04am UTC](https://www.ruby-forum.com/t/partials-problem/109012/3 "2007-07-11T11:04:14Z")

</div>

Thanks for the reply, Jodi.

I’ve just downloaded and installed the firebug plugin. Having never used  
it could you point me in the right direction as to under which tab I  
should be looking?

P.S. The script is now working as it should - in IE only…

I have one line for script name, description, path.

Then underneath it one line for metadata name and metadata value with an  
‘add another’ button to add more metadata name/value pairs.

When multiple name/value pairs are input, IE stores all of them in the  
database. Wheras Firefox only stores the very first pair. Can you  
suggest why this is?
