I'm trying to pre-populate a string field in a form when a link is clicked. I've tried:
$<%= link_to "New product", new_product_path(:product_name => "foo") %>
and
$<%= link_to "New product", new_product_path(:name => "foo") %>
Both didn't work. Anyone has any idea?
Try this,
<%= f.text_field :name,:value=>(@product.new_record? ? params[:name] : @product.name )%>
or in new action
def new
@product = Product.new(:name=>params[:name])
end
<%= f.text_field :name %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With