I have a piece of html like this:
<div class="row well">
<form method="POST">
<ol id="velArea">
<li> Layer velocity: (m/s) <input type="text" name="source[]"> </li>
</ol>
<input type="button" value="Add another layer" name="velocity" onClick="addVel('velArea');">
</form>
</div>
and a javascript function that adds html to the area
function addVel(area)
{
var field_area = document.getElementById(area);
field_area.innerHTML += "<li> Layer velocity: (m/s) <input type='text' name='velocity'> <a style='cursor:pointer;color:grey;' onclick='this.parentNode.parentNode.removeChild(this.parentNode);''>delete</a> </li>";
}
I need to read the value of each input field in a rails function. And have no idea about how to do that. I've lost days going through active model in rails, thinking that was the way until I finally figured out that is better to keep the browser-related and server related things separated. So I learned a little javascript and made a few functions. Yes, I'm new to web development. I'm using rails 3.2.
The function that I want to uses the fields info is called by a button:
<%= button_to "Run single inversion", {:action => "my_func", }, {:remote => true, :form => { "data-type" => "json" }, :class => "btn btn-primary"} %>
and the function on the controller is:
def my_func
render :nothing => true
vel = params[:velocity]
puts vel.class
puts 'Hi'
end
the output I get is
NilClass
Hi
so I'm clearly not passing the arguments right. I'm guessing I need to pass the velocity array in the post method when I use the button_to, but have no idea about how to do that.
Also, I'm need the value of the input, not anything database oriented so I cannot look it up using activeRecord properties.