Andrey Skuratovsky
Andrey Skuratovsky

Reputation: 687

Rails simple_from: specify model id in input id

Simple Form generates by default id for inputs in form some this way id="#{model_name}_#{attr_name}".

I need to include id of model in this input id, because i have several forms of models on single page (nested). So id would be like id="#{model_name}_#{model_ID}_#{attr_name}"

By example

= simple_form_for([@site, supply]) do |f|
  = f.input :name
  ...

Generates form like it:

<form ... id="edit_supply_4">
  <input ... id="supply_name" ... >

But i need this:

<form ... id="edit_supply_4">
  <input ... id="supply_4_name" ... >

How to do this?

Upvotes: 0

Views: 190

Answers (1)

max
max

Reputation: 102443

Passing a input_html hash allows you to customise the attributes of the input:

= simple_form_for([@site, supply]) do |f|
  = f.input :name, :input_html => {
    :id => "#{@site.model_name}_#{@site.id}_name"
  }

Upvotes: 1

Related Questions