When i use rails, i create a simple form using simple form gem
I create a form like this
<%= simple_form_for @user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
but i would like to add an default image element just next to each fields. how can i achieve that?
i try this
<%= simple_form_for @user do |f| %>
<%= f.input :username % >
<img xxxx>
<%= f.input :password %>
<img xxxx>
<%= f.button :submit %>
<img xxxx>
<% end %>
but i won't work as it would wrap into a new line for each element field.
Well the answer for that is is like this create a folder called input in the app/
and create a file with [any_name]_input.rb let say you name it image_tag_input.rb
then the code inside the image_tag_input.rb look like this
class ImageTagInput < SimpleForm::Inputs::Base
## Because image tage doesnot work if not included the below
include ActionView::Helpers::AssetTagHelper
def input
("#{@builder.text_field(attribute_name, input_html_options)}" + "#{image_tag()}).html_safe
end
end
and then on the html side
do this
<%= f.input :username,:as => "image_tag %>
Here and another example mention in wiki of the simple_form_for
Hope this help
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