在轨道中使用图像作为单选按钮

时间:2017-10-06 17:20:01

标签: ruby-on-rails image radio-button

如何在轨道中使用本地图像作为单选按钮?

我猜可以使用collection_radio_buttons帮助器,但是如何集成本地图像呢?

此代码段显示了带有以下文字的单选按钮:

cfg.CreateMap<Dto.Member, Member>()
    .ConstructUsing((memberDto, context) => {
    switch (memberDto.MemberType)
    {
        case "PersonMember":
            return context.Mapper.Map<PersonMember>(memberDto);
        case "CompanyMember":
            return context.Mapper.Map<CompanyMember>(memberDto);
        default:
            throw new ArgumentOutOfRangeException($"Unknown MemberType {memberDto.MemberType}");
    }
});

cfg.CreateMap<Dto.Member, PersonMember>()
    .ForMember(dest => PersonMember.PersonMemberId,
               opt => opt.MapFrom(src => src.MemberId));

cfg.CreateMap<Dto.Member, CompanyMember>()
    .ForMember(dest => CompanyMember.CompanyMemberId,
               opt => opt.MapFrom(src => src.MemberId));

我是否必须将 b.radio_button 替换为 image_tag

1 个答案:

答案 0 :(得分:1)

是,而不是b.text,您可以使用image_tag显示图片而不是文字

#I have image in app/assets/images   as One.png,Two.png and so on.

<%= f.collection_radio_buttons(:paket, [[1, 'One'] ,[2, 'Two'], [3, 'Three']], :first, :last) do |b| %>
  <%= b.label { b.radio_button + image_tag('/'+b.text+'.png') } %>
<% end %>