笑故挽风 2012-06-28 10:52 采纳率: 100%
浏览 9

Rails 3.1-Ajax单选按钮

I'm trying to add a HighCharts chart to my Rails app, the content of which will be determined by the selection of radio buttons. My code for the radio buttons is fairly standard and is as follows:

  <%= radio_button_tag(:interface, "wlan") %>
  <%= label_tag(:interface_wlan, "WLAN") %>
  <%= radio_button_tag(:interface, "3g") %>
  <%= label_tag(:interface_3g, "3G") %>

I see Rails 3.1 has the "remote => :true" option to make Ajax much simpler. My question is where exactly do I put this option for a series of radio buttons? I tried adding it at the end of the radio_button_tag parameters, but it didn't generate the appropriate HTML.

Alternatively, if there is a simpler way of doing what I want to do I'd be open to that as well.

  • 写回答

1条回答 默认 最新

  • weixin_33735676 2012-06-28 13:29
    关注

    You can do this using jquery. In my opinion is far easier to do this way.
    You put the code in your your_model.js file, create the ajax function like the code below.
    Create a custom route and do whatever you want.

    $("#wlan").click(function() {
      $.ajax({
        type: "TYPE_OF_REQUEST",
        url: "/your_url",
        success: function(data) {
          ... Your success behavior here ...
        },
        error: function(data) {
          ... Your error behavior here ...
        }
      });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题