简体   繁体   English

jQuery UI对话框显示操作(Rails 3)

[英]JQuery UI dialog display action (Rails 3)

Before I start, I'm a beginner at javascript, rails 3 and jQuery so please provide full examples. 在开始之前,我是javascript,rails 3和jQuery的初学者,因此请提供完整的示例。

Here is what i'm trying to do: I have build a rails app with scaffold and changed the default javascript to jQuery in order to make a piechart on the dashboard work. 这是我想做的事情:我已经用脚手架构建了Rails应用程序,并将默认的javascript更改为jQuery,以使仪表板上的饼图起作用。

So now I though I could add the jQuery UI and display a dialog box with a Show action of the created scaffold when someone clicks on Show. 因此,现在我可以添加jQuery UI并在有人单击“显示”时显示一个对话框,其中包含创建的支架的“显示”动作。

The title of the dialog box must be the id. 对话框的标题必须是ID。

Unfortunately everything I've tried so far has not worked. 不幸的是,到目前为止,我尝试过的所有方法均无效。

I've tried things like: , :remote => true, 我已经尝试过类似的东西:,:remote => true,

I think the biggest problem is, is that a POST is executed (at least if i look in the errors in the terminal, it says: 我认为最大的问题是执行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"):

I think a GET should be executed. 我认为应该执行GET。

Here's my full index file: 这是我的完整索引文件:

<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>

I know that it is 1 big mess right now, but that's because I've been trying a lot of things so I've changed some tags to allow new things to work. 我知道现在是1大混乱,但这是因为我一直在尝试很多事情,所以我更改了一些标签以允许新事物起作用。

The only thing that has worked so far but didn't give me a Show action, just a regular Dialog with some options is the: #opeaner one 到目前为止唯一有效但没有给我Show动作的东西,只是带有某些选项的常规Dialog是:#opeaner

Thank you so much! 非常感谢! very appreciated! 非常感激!

尝试在链接中指定方法(在这种情况下为:get),以执行show动作:

<%= link_to 'Show', trip, 'id' => 'showdialog', :remote => true, :method => :get %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM