单击rails中的URL时如何弹出面板? [英] How to popup a panel when clicking a URL in rails?

查看:83
本文介绍了单击rails中的URL时如何弹出面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是rails的新手,我需要知道如何通过点击URL来弹出面板?请有人给我解决这个问题的方法。

I'm new to rails and I need to know how to pop-up a panel by clicking a URL ?? Please can some one give me solution for this problem.

推荐答案

您可以通过www.jqueryui.com查看模态对话框。将jquery ui添加到您的应用程序中。

You could look at modal dialogs by www.jqueryui.com. Add jquery ui to your application.

在布局页面中放置一个隐藏的div(display:none)。

Put a hidden div (display:none) in your layout page.

<div class="modal" style="display:none;">
</div>

您的链接应该是ajax链接:

Your link should be an ajax link:

<%= link_to 'Link', events_path(@event), :remote => true %>

您的控制器应接受ajax响应:

Your controller should accept ajax response:

def show
  @event = Event.find(params[:id])
  respond_to do |format|
    format.js
  end
end

这是魔术发生了。通过ajax按下链接后,show.js文件会将内容插入到空的隐藏div中并显示弹出窗口。您的观点应该有一个javascript文件:/view/events/show.js.erb

This is where the magic happens. After pressing the link via ajax, your show.js file will insert content into your empty hidden div and display the popup. Your views should have a javascript file: /view/events/show.js.erb

$('.modal').html("<%= escape_javascript(render(@event)) %>"); //inserts content into your empty div, be aware that the parameter needed to be quoted.
$('.modal').dialog(); //jquery ui will open it as a modal popup

在上面的示例中,它将呈现一个事件部分。所以你应该通过在/ views / events /

In the example above it will render an event partial. So you should make it by creating an _event.html.erb file in /views/events/

这篇关于单击rails中的URL时如何弹出面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆