Question: I have two models in Rails 3 - a User model and a Profile model.

```
class User < ActiveRecord::Base
  has_one :profile, :dependent => :destroy
end

class Profile < ActiveRecord::Base
  belongs_to :user
end

```

They are scoped in my routes.rb file, as such:

```
resources :users do
  resources :profiles
end

```

So now, my form to create a profile reads like this (Using SimpleForm):

```
<%= simple_form_for([@user, @profile]) do |f| %>
  <%= f.error_notification %>
    ...(Other Inputs)
<% end %>

```

However, the user ID doesn't seem to be automatically sent to the profile model as I had assumed. Do I have to set that manually through the controller? Or am I missing something?

Answer: 
First off, get that `script` to the bottom of the `body`, right before the `</body>`. Putting it anywhere else will block page loading. Adapt your HTML for proper DOM manipulation by giving IDs to the elements you're going to manipulate:

```
<table>
    <thead>
        <tr><th>Celsius</th><th>Fahrenheit</th></tr>
    </thead>
    <tbody id="temperatureTableTbody"></tbody>
</table>
<script type="text/javascript" src="temperatures.js"></script>
</body>

```

Also make a closure to don't pollute the global scope with unnecessary variables. I modified your code slightly to use proper DOM manipulation, should work on any browser released in the last decade.

```
(function() { //creates a closure, so vars don't leak in the global scope
    //stores a reference to the tbody DOM element which we will append rows to
    var tbody = document.getElementById('temperatureTableTbody');
    //iterates celsius from 0 to 50
    for (var celsius = 0; celsius <= 50; celsius++) {
        //creates elements
        var tr = document.createElement('tr'),
            tdcelsius = document.createElement('td'),
            tdfahr = document.createElement('td');
        //append textNodes to the td elements
        tdcelsius.appendChild(document.createTextNode(celsius));
        tdfahr.appendChild(document.createTextNode((celsius*9/5)+32));
        //appends the tds to the tr
        tr.appendChild(tdcelsius);
        tr.appendChild(tdfahr);
        //append the finished row to the tbody
        tbody.appendChild(tr);
        //repeat loop while condition is true
    }
}());​ //closes the Immediately Invoked Function Expression

```

[**Fiddle**](http://jsfiddle.net/rpytJ/)

And please, don't use `document.write`.

Some reference: [Why is document.write considered a 'bad practice'?](https://stackoverflow.com/a/802943/1331430)
You should call a javascript function when document has been loaded:

```
if (document.readyState === "complete") { loadTemperatures(); }

```

Your loadTemperatures function will append rows to your table. Have a look here to learn how to do that:
<http://viralpatel.net/blogs/dynamically-add-remove-rows-in-html-table-using-javascript/>

> 
> Element script not allowed as child of element tbody in this context
> 
> 
> 

Put the `<script>` balise between `<head>` and `</head>` to correct that.

Here is a jsFiddle to show you the goal: <http://jsfiddle.net/dfTz6/2/>