7

このフォーラムの質問はどれも、私の特定のニーズに対応していないようです。基本的に、「詳細」ボタンがあります。クリックすると、モデルの show.html.erb から引き出された情報を含むモーダル ダイアログが表示されるようにします。私は book.rb モデルを持っています。インデックスページには次のものがあります:

<div class="detail_button"><%= link_to "Details", book %></div>

通常、このボタンをクリックすると、show アクションを使用して book/id ページに移動します。しかし、ページを離れたくないので、閉じることができるモーダルポップアップが必要です。このフォーラムの関連トピックですべての jquery および javascript コードを試しましたが、うまくいかないようです。ほとんどは、アクションの作成またはカスタムのみに対処しているようです。

繰り返しを避けるために、次のことを試しましたが、どれもうまくいきませんでした:

これ:

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

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

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

Your link should be an ajax link:

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

Your controller should accept ajax response:

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

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.
$('.modal').dialog(); //jquery ui will open it as a modal popup

これ:

$('a[data-popup]').live('click', function(e) { 
    window.open($(this).attr('href')); 
    e.preventDefault(); 
}); 

この:

$('a[data-popup]').live('click', function(e) { window.open($(this).attr('href')); e.preventDefault(); });

= link_to( 'Create a new company', new_company_path, 'data-popup' => true )

助けてくれる人はいますか?ここで完全な初心者。

4

2 に答える 2