[英]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.