2012-05-08 13 views
0

この問題を検索したが解決策を見つけることができなかった。Rails/Facebox - リモート機能による更新

私は、フォームの以前の要素の選択に応じて部分的に置き換えられる要素を持つフォームを持っています(たとえば、ユーザーが "Origin"を選択すると、フォームは "Destinations"コレクションを選択します)選択された起源から利用可能)。 これはうまくいきます。ただし、Faceboxポップアップでフォームがモーダルに表示されるようにしたい場合を除きます。

現在のフォームが正しくしかし、フォーム要素には何のonchangeアクションが更新されているように見えるんfaceboxポップアップ負荷...ビューで


<%= link_to "New Delivery", new_delivery_requests_path, :remote => true %>

リモートコール(ビュー/ delivery_requests /new.js.erb):
$.facebox('<%= escape_javascript(render 'new') %>')

新レイアウト(ビュー/ delivery_requests/new.html.erb):

<%= form_for @price_update do |f| %> 
    <% if @price_update.errors.any? %> 
    <h2>Errors:</h2> 
    <ul> 
     <% @price_update.errors.full_messages.each do |message|%> 
     <li><%= message %> </li> 
     <% end %> 
    </ul> 
    <% end %> 
    <br /> 
    <table> 
     <tr> 
      <td><%= f.label "Select origin location: "%> </td> 
      <td><%= collection_select(:route, :origin_id, @origins, :id, :name, 
      { :prompt => "Please select an origin" }, 
      { :onchange => "#{remote_function(
       :url => { :action => "update_destinations"}, 
       :with => "'origin_id='+value")}", 
       :id => "origin_select"})%> 
      </td> 
     </tr> 
     <tr> 
      <td><%= f.label "Select destination location: "%> </td> 
      <td><div id="destinations"> 
       <%= collection_select(:route, :destination, 
       @available_routes, :id, :destination, 
       { :prompt => "Please select an origin first" }, { :disabled => "disabled" })%></div></td> 
     </tr>    
     <tr> 
      <td><%= f.label "Current Prices: "%> </td> 
      <td> 
       <div id="current-prices-table"></div> 
      </td> 
     </tr> 
     <tr> 
      <td><%= f.label "Please select price option" %></td> 
      <td> 
       <div id = "price-selection"></div> 
      </td> 
     </tr> 
     <tr> 
      <td><%= f.label "Priority" %></td> 
      <td><%= f.label "Price Per Gram" %></td> 
      <td><%= f.label "Price per cm3" %></td> 
     </tr> 
     <tr> 
      <td><div id="priority-label"></div></td> 
      <td><%= f.text_field :new_price_per_gram, :id => "price_per_gram_textfield" %></td> 
      <td><%= f.text_field :new_price_per_vol, :id => "price_per_vol_textfield" %></td> 
     </tr> 
    </table> 
    <br /> 
    <%= f.submit "Update Prices"%> 
<% end %> 

そしてdelivery_requestsコントローラ内の更新先のアクション:

def update_destinations 
    # updates the available list of destinations after an 
    # origin location has been chosen when making a new delivery request 
    sel_origin = Location.find(params[:origin_id]) 
    @available_routes = Route.find_available_routes(sel_origin.name) 
    render :update do |page| 
     page.replace_html 'destinations', :partial => 'destinations_select', :object => @destinations 
    end 
    end 

私はレールにかなり新しいです - どんな助言も施されるだろう。

答えて

1

私は今夜自分自身に苦労していて、ついに答えが出ました。開いているfaceboxを参照する必要があります。これはあなたのものを働かせるためにあなたがするものです。

def update_destinations 
# updates the available list of destinations after an 
# origin location has been chosen when making a new delivery request 
sel_origin = Location.find(params[:origin_id]) 
@available_routes = Route.find_available_routes(sel_origin.name) 
render :update do |page| 
    page << "jQuery('#facebox .content #destinations').replaceWith(#{(render :partial => 'destinations_select', :object => @destinations).to_json})"  
end 
end 

私は答えを構築https://github.com/ihower/facebox_render/blob/master/lib/facebox_render.rbに私を導いたjQuery .on not working with dynamic DOM/HTMLを感謝しなければなりません。

+0

お返事ありがとうございます。当時私は別のアプローチをとっていたと思いますが、これが他の人を助けることができれば幸いです。乾杯。 – jmc

関連する問題