I want to repeat a form element using jquery's .before(); method , so that users of the form can add more ingredients in this case to their recipe.
So far I have come up with this, however I cant use ruby code in a js file
$('document').ready(function() {
var ingredient = '<%= f.text_field :ingredients, :class => :ingred %><br>';
$('#addIngredient').click(function(e) {
e.preventDefault();
$(this).before(ingredient);
})
});
I have done it using html5 and had it working doing this
$('document').ready(function() {
var ingredient = '<input class="ingredients" name="ingredients" type="text" placeholder="Enter Ingredients Here"><br>';
$('#addingredient').click(function(event) {
event.preventDefault();
$(this).before(ingredient);
})
});
Im just having trouble getting this to fit in with my ruby form
at the moment i get this outputted to the page rather than the text field
<%= f.text_field :ingredients, :class => :ingred %>
Can anyone help? Much appreciated
=]