[英]JQuery UI dialog display action (Rails 3)
在开始之前,我是javascript,rails 3和jQuery的初学者,因此请提供完整的示例。
这是我想做的事情:我已经用脚手架构建了Rails应用程序,并将默认的javascript更改为jQuery,以使仪表板上的饼图起作用。
因此,现在我可以添加jQuery UI并在有人单击“显示”时显示一个对话框,其中包含创建的支架的“显示”动作。
对话框的标题必须是ID。
不幸的是,到目前为止,我尝试过的所有方法均无效。
我已经尝试过类似的东西:,:remote => true,
我认为最大的问题是执行POST(至少如果我查看终端中的错误,它会说:
Started POST "/trips/1" for 127.0.0.1 at Sun Sep 19 11:07:24 +0200 2010
ActionController::RoutingError (No route matches "/trips/1"):
我认为应该执行GET。
这是我的完整索引文件:
<h1>Listing trips</h1>
<table>
<tr>
<th>License</th>
<th>Contract</th>
<th>Time</th>
<th></th>
</tr>
<% @trips.each do |trip| %>
<tr>
<td><%= trip.license %></td>
<td><%= trip.contract %></td>
<td><%= trip.time %></td>
<td><%= link_to 'Show', trip, 'class'=>"ajax", :remote => true %></td>
<td><%= link_to 'Show', trip, 'class'=>"ajax" %></td>
<td><%= link_to 'Show', trip, 'id' => 'opener', :remote => true %></td>
<td><%= link_to 'Show', trip, 'id' => 'opener' %></td>
<td><%= link_to 'Show', trip, 'id' => 'showdialog', :remote => true %></td>
</tr>
<% end %>
</table>
<div id="example"></div>
<script type="text/javascript">
$(document).ready(function(){
var dialogOpts = {
modal: true,
bgiframe: true,
autoOpen: false,
height: 500,
width: 500,
draggable: true,
resizeable: true,
};
$("#example").dialog(dialogOpts); //end dialog
$('#showdialog').click(
function() {
$("#example").load(this.href, type: 'get', function(){
$("#example").dialog("open");
}
);
return false;
}
);
});
</script>
<script type="text/javascript">
$(document).ready(function() {
var dialogOpts = {
autoOpen: false,
title: 'Trip: Trip Number comes here',
modal: true,
height: 600,
width: 600,
draggable: false,
resizable: false
}
var $dialog = $('<div></div>')
.html('Must become show action!')
.dialog(dialogOpts);
$('ae[data-remote=true]').live('click', function() {
$dialog.dialog('open');
return false;
});
$('#opeaner').click(function() {
$dialog.dialog('open');
// prevent the default action, e.g., following a link
return false;
});
});
$(function (){
$('aa.ajax').click(function() {
var url = this.href;
var dialog = $('<div></div>');
// load remote content
jQuery.ajax({type: 'GET'})
dialog.load(
url,
{},
function (responseText, textStatus, XMLHttpRequest) {
dialog.dialog();
}
);
//prevent the browser to follow the link
return false;
});
});
var request = function(options) {
$.ajax($.extend({ url : options.url, type : 'get' }, options));
return false;
};
// remote links handler
$('a[data-remote=true]').live('click', function() {
return request({ url : this.href });
});
</script>
我知道现在是1大混乱,但这是因为我一直在尝试很多事情,所以我更改了一些标签以允许新事物起作用。
到目前为止唯一有效但没有给我Show动作的东西,只是带有某些选项的常规Dialog是:#opeaner
非常感谢! 非常感激!
尝试在链接中指定方法(在这种情况下为:get),以执行show动作:
<%= link_to 'Show', trip, 'id' => 'showdialog', :remote => true, :method => :get %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.