我有一个包含这样的行的表单。当用户单击单选按钮时,我需要能够使用ajax / jquery在控制器上调用方法。该方法将更改底层模型,返回时它将在客户端的flash中显示一条消息。
<tr>
<td><%= radio_button_tag 'primary', feature_photo.id %></td>
<td>
<%= feature_photo.name %>
By: <%= feature_photo.photo_credit %>
</td>
<tr>
答案 0 :(得分:0)
您正在寻找observe_field。其余的就像任何其他rails操作一样简单(控制器中的一个动作返回与文本,javascript等相关的内容)。
你也提到了jQuery,但你在应用中如何使用它并不明显。 observe_field
将生成Prototype代码,而不是jQuery。如果你有一些jQuery,你可以为单选按钮编写一个处理程序,也许是这样:
$('#primary').bind( 'change', function() {
$.ajax( {
url: 'some_rails_action',
data: $(this).is(':checked'),
success: function( r ) {
// do something with the response from rails here
}
} );
} );
有了更多细节,我可以提供更全面的帮助:)