Search code examples
ruby-on-railsrubyhamlbutton-to

Change image_tag to button_to


I'm trying to figure out how to change this code:

%li.input.optional= link_to_remove_association image_tag('minus.png', {:alt => "#{t('blabla.remove_model', model: t('activerecord.models.template_instance_right.one'))}"}), f

to use a button instead. It's the first time I use Rails so I'm a bit lost.

I tried:

=button_to('Remove', {:alt => "#{t('blabla.remove_model', model: t('activerecord.models.template_instance_right.one'))}"})

which does display the button but it doesn't delete the record.

I think I need to use link_to_remove_association but I don't know how to combine it with a button essentially. Any ideas ?


Solution

  • Just replace image_tag with button_tag tag:

    %li.input.optional= link_to_remove_association button_tag('Remove', {:alt => "#{t('blabla.remove_model', model: t('activerecord.models.template_instance_right.one'))}"})