2012-06-01 54 views
0

我正在使用Formtastic,我試圖設置一個遠程表單來訪問編輯操作而不離開當前頁面並轉到/ 1 /編輯類型url。Formtastic遠程表格

我的格式如下:

<%= semantic_form_for shipdr_website, :url => edit_shipdr_website_path(shipdr_website), :html => { :method => :post }, :remote => true do |f| %> 
    <%= f.input :name, :input_html => { :value => shipdr_website.name } %> 
    <%= f.input :url, :input_html => { :value => shipdr_website.url } %> 
    <%= f.input :api_key, :input_html => { :value => shipdr_website.api_key } %> 
    <%= f.actions %> 
<% end %> 

視圖位於下shipdr /儀表/網站,短跑視圖控制器沒有,所以我需要使用遠程形式訪問有一個編輯動作不同控制器的編輯方法。

表單顯示和頁面加載不顯示任何錯誤,但是,當我點擊「創建網站」按鈕時,沒有任何事情發生。如果我刪除第一行的remote => true部分,那麼當我單擊按鈕時,我會得到No route matches [POST] "/shipdr/websites/14/edit"

下面是使用耙路線我的路線:

shipdr_dashboard_dashboard  /shipdr/dashboard/dashboard(.:format)  {:controller=>"shipdr/dashboard", :action=>"dashboard"} 
      shipdr_websites GET /shipdr/websites(.:format)     {:action=>"index", :controller=>"shipdr/websites"} 
          POST /shipdr/websites(.:format)     {:action=>"create", :controller=>"shipdr/websites"} 
     new_shipdr_website GET /shipdr/websites/new(.:format)    {:action=>"new", :controller=>"shipdr/websites"} 
     edit_shipdr_website GET /shipdr/websites/:id/edit(.:format)   {:action=>"edit", :controller=>"shipdr/websites"} 
      shipdr_website GET /shipdr/websites/:id(.:format)    {:action=>"show", :controller=>"shipdr/websites"} 
          PUT /shipdr/websites/:id(.:format)    {:action=>"update", :controller=>"shipdr/websites"} 
          DELETE /shipdr/websites/:id(.:format)    {:action=>"destroy", :controller=>"shipdr/websites"} 
      shipdr_carriers GET /shipdr/carriers(.:format)     {:action=>"index", :controller=>"shipdr/carriers"} 
          POST /shipdr/carriers(.:format)     {:action=>"create", :controller=>"shipdr/carriers"} 
     new_shipdr_carrier GET /shipdr/carriers/new(.:format)    {:action=>"new", :controller=>"shipdr/carriers"} 
     edit_shipdr_carrier GET /shipdr/carriers/:id/edit(.:format)   {:action=>"edit", :controller=>"shipdr/carriers"} 
      shipdr_carrier GET /shipdr/carriers/:id(.:format)    {:action=>"show", :controller=>"shipdr/carriers"} 
          PUT /shipdr/carriers/:id(.:format)    {:action=>"update", :controller=>"shipdr/carriers"} 
          DELETE /shipdr/carriers/:id(.:format)    {:action=>"destroy", :controller=>"shipdr/carriers"} 
      shipdr_countries GET /shipdr/countries(.:format)     {:action=>"index", :controller=>"shipdr/countries"} 
          POST /shipdr/countries(.:format)     {:action=>"create", :controller=>"shipdr/countries"} 
     new_shipdr_country GET /shipdr/countries/new(.:format)    {:action=>"new", :controller=>"shipdr/countries"} 
     edit_shipdr_country GET /shipdr/countries/:id/edit(.:format)  {:action=>"edit", :controller=>"shipdr/countries"} 
      shipdr_country GET /shipdr/countries/:id(.:format)    {:action=>"show", :controller=>"shipdr/countries"} 
          PUT /shipdr/countries/:id(.:format)    {:action=>"update", :controller=>"shipdr/countries"} 
          DELETE /shipdr/countries/:id(.:format)    {:action=>"destroy", :controller=>"shipdr/countries"} 
    shipdr_shipping_groups GET /shipdr/shipping_groups(.:format)   {:action=>"index", :controller=>"shipdr/shipping_groups"} 
          POST /shipdr/shipping_groups(.:format)   {:action=>"create", :controller=>"shipdr/shipping_groups"} 
    new_shipdr_shipping_group GET /shipdr/shipping_groups/new(.:format)  {:action=>"new", :controller=>"shipdr/shipping_groups"} 
edit_shipdr_shipping_group GET /shipdr/shipping_groups/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_groups"} 
     shipdr_shipping_group GET /shipdr/shipping_groups/:id(.:format)  {:action=>"show", :controller=>"shipdr/shipping_groups"} 
          PUT /shipdr/shipping_groups/:id(.:format)  {:action=>"update", :controller=>"shipdr/shipping_groups"} 
          DELETE /shipdr/shipping_groups/:id(.:format)  {:action=>"destroy", :controller=>"shipdr/shipping_groups"} 
     shipdr_shipping_rules GET /shipdr/shipping_rules(.:format)   {:action=>"index", :controller=>"shipdr/shipping_rules"} 
          POST /shipdr/shipping_rules(.:format)   {:action=>"create", :controller=>"shipdr/shipping_rules"} 
    new_shipdr_shipping_rule GET /shipdr/shipping_rules/new(.:format)  {:action=>"new", :controller=>"shipdr/shipping_rules"} 
    edit_shipdr_shipping_rule GET /shipdr/shipping_rules/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_rules"} 
     shipdr_shipping_rule GET /shipdr/shipping_rules/:id(.:format)  {:action=>"show", :controller=>"shipdr/shipping_rules"} 
          PUT /shipdr/shipping_rules/:id(.:format)  {:action=>"update", :controller=>"shipdr/shipping_rules"} 
          DELETE /shipdr/shipping_rules/:id(.:format)  {:action=>"destroy", :controller=>"shipdr/shipping_rules"} 
    shipdr_shipping_methods GET /shipdr/shipping_methods(.:format)   {:action=>"index", :controller=>"shipdr/shipping_methods"} 
          POST /shipdr/shipping_methods(.:format)   {:action=>"create", :controller=>"shipdr/shipping_methods"} 
new_shipdr_shipping_method GET /shipdr/shipping_methods/new(.:format)  {:action=>"new", :controller=>"shipdr/shipping_methods"} 
edit_shipdr_shipping_method GET /shipdr/shipping_methods/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_methods"} 
    shipdr_shipping_method GET /shipdr/shipping_methods/:id(.:format)  {:action=>"show", :controller=>"shipdr/shipping_methods"} 
          PUT /shipdr/shipping_methods/:id(.:format)  {:action=>"update", :controller=>"shipdr/shipping_methods"} 
          DELETE /shipdr/shipping_methods/:id(.:format)  {:action=>"destroy", :controller=>"shipdr/shipping_methods"} 
     shipdr_ship_filters GET /shipdr/ship_filters(.:format)    {:action=>"index", :controller=>"shipdr/ship_filters"} 
          POST /shipdr/ship_filters(.:format)    {:action=>"create", :controller=>"shipdr/ship_filters"} 
    new_shipdr_ship_filter GET /shipdr/ship_filters/new(.:format)   {:action=>"new", :controller=>"shipdr/ship_filters"} 
    edit_shipdr_ship_filter GET /shipdr/ship_filters/:id/edit(.:format)  {:action=>"edit", :controller=>"shipdr/ship_filters"} 
     shipdr_ship_filter GET /shipdr/ship_filters/:id(.:format)   {:action=>"show", :controller=>"shipdr/ship_filters"} 
          PUT /shipdr/ship_filters/:id(.:format)   {:action=>"update", :controller=>"shipdr/ship_filters"} 
          DELETE /shipdr/ship_filters/:id(.:format)   {:action=>"destroy", :controller=>"shipdr/ship_filters"} 
       shipdr_zones GET /shipdr/zones(.:format)      {:action=>"index", :controller=>"shipdr/zones"} 
          POST /shipdr/zones(.:format)      {:action=>"create", :controller=>"shipdr/zones"} 
      new_shipdr_zone GET /shipdr/zones/new(.:format)     {:action=>"new", :controller=>"shipdr/zones"} 
      edit_shipdr_zone GET /shipdr/zones/:id/edit(.:format)   {:action=>"edit", :controller=>"shipdr/zones"} 
       shipdr_zone GET /shipdr/zones/:id(.:format)     {:action=>"show", :controller=>"shipdr/zones"} 
          PUT /shipdr/zones/:id(.:format)     {:action=>"update", :controller=>"shipdr/zones"} 
          DELETE /shipdr/zones/:id(.:format)     {:action=>"destroy", :controller=>"shipdr/zones"} 
     new_admin_user_session GET /admin_users/sign_in(.:format)    {:action=>"new", :controller=>"devise/sessions"} 
      admin_user_session POST /admin_users/sign_in(.:format)    {:action=>"create", :controller=>"devise/sessions"} 
    destroy_admin_user_session DELETE /admin_users/sign_out(.:format)    {:action=>"destroy", :controller=>"devise/sessions"} 
     admin_user_password POST /admin_users/password(.:format)    {:action=>"create", :controller=>"devise/passwords"} 
    new_admin_user_password GET /admin_users/password/new(.:format)   {:action=>"new", :controller=>"devise/passwords"} 
    edit_admin_user_password GET /admin_users/password/edit(.:format)   {:action=>"edit", :controller=>"devise/passwords"} 
          PUT /admin_users/password(.:format)    {:action=>"update", :controller=>"devise/passwords"} 
      new_user_session GET /users/sign_in(.:format)      {:action=>"new", :controller=>"devise/sessions"} 
       user_session POST /users/sign_in(.:format)      {:action=>"create", :controller=>"devise/sessions"} 
     destroy_user_session DELETE /users/sign_out(.:format)     {:action=>"destroy", :controller=>"devise/sessions"} 
     user_omniauth_callback  /users/auth/:action/callback(.:format)  {:action=>/google/, :controller=>"omniauth/omniauth_callbacks"} 
       user_password POST /users/password(.:format)     {:action=>"create", :controller=>"devise/passwords"} 
      new_user_password GET /users/password/new(.:format)    {:action=>"new", :controller=>"devise/passwords"} 
      edit_user_password GET /users/password/edit(.:format)    {:action=>"edit", :controller=>"devise/passwords"} 
          PUT /users/password(.:format)     {:action=>"update", :controller=>"devise/passwords"} 
    cancel_user_registration GET /users/cancel(.:format)      {:action=>"cancel", :controller=>"devise/registrations"} 
      user_registration POST /users(.:format)        {:action=>"create", :controller=>"devise/registrations"} 
     new_user_registration GET /users/sign_up(.:format)      {:action=>"new", :controller=>"devise/registrations"} 
     edit_user_registration GET /users/edit(.:format)      {:action=>"edit", :controller=>"devise/registrations"} 
          PUT /users(.:format)        {:action=>"update", :controller=>"devise/registrations"} 
          DELETE /users(.:format)        {:action=>"destroy", :controller=>"devise/registrations"} 
         users GET /users(.:format)        {:action=>"index", :controller=>"users"} 
          POST /users(.:format)        {:action=>"create", :controller=>"users"} 
        new_user GET /users/new(.:format)       {:action=>"new", :controller=>"users"} 
        edit_user GET /users/:id/edit(.:format)     {:action=>"edit", :controller=>"users"} 
         user GET /users/:id(.:format)       {:action=>"show", :controller=>"users"} 
          PUT /users/:id(.:format)       {:action=>"update", :controller=>"users"} 
          DELETE /users/:id(.:format)       {:action=>"destroy", :controller=>"users"} 
       pages_contact GET /pages/contact(.:format)      {:controller=>"pages", :action=>"contact"} 
       pages_pricing GET /pages/pricing(.:format)      {:controller=>"pages", :action=>"pricing"} 
       pages_features GET /pages/features(.:format)     {:controller=>"pages", :action=>"features"} 
      pages_howitworks GET /pages/howitworks(.:format)     {:controller=>"pages", :action=>"howitworks"} 
        pages_home GET /pages/home(.:format)      {:controller=>"pages", :action=>"home"} 
        settings  /settings(.:format)       {:controller=>"pages", :action=>"settings"} 
          GET /shipdr/dashboard/dashboard(.:format)  {:controller=>"shipdr/dashboard", :action=>"dashboard"} 
    shipdr_dashboard_rules GET /shipdr/dashboard/rules(.:format)   {:controller=>"shipdr/dashboard", :action=>"rules"} 
     shipdr_dashboard_ship GET /shipdr/dashboard/ship(.:format)   {:controller=>"shipdr/dashboard", :action=>"ship"} 
    shipdr_dashboard_validate GET /shipdr/dashboard/validate(.:format)  {:controller=>"shipdr/dashboard", :action=>"validate"} 
shipdr_dashboard_analytics GET /shipdr/dashboard/analytics(.:format)  {:controller=>"shipdr/dashboard", :action=>"analytics"} 
    shipdr_dashboard_carriers GET /shipdr/dashboard/carriers(.:format)  {:controller=>"shipdr/dashboard", :action=>"carriers"} 
    shipdr_dashboard_websites GET /shipdr/dashboard/websites(.:format)  {:controller=>"shipdr/dashboard", :action=>"websites"} 
         root  /           {:controller=>"pages", :action=>"home"} 

搞清楚了這一點任何幫助,將不勝感激。

回答

0

你檢查了你的routes.rb文件嗎?給我們的耙路線信息

您的控制器設置爲ajax請求?

您是否有必要的javascript作用於語義形式?

這些是你的表單工作的事情。

查看https://gist.github.com/548387?file=tickets_controller.rb瞭解您需要的hwat。

+0

謝謝你的迴應。我發佈了我的耙路線。我會考慮是否已經爲ajax正確設置了我的控制器,以及是否有必要的Javascript。 – user1152142

+0

嗯,有一件事,你的edit_shipdir路徑期待GET,你將它傳遞給POST – TheIrishGuy

+0

是的,我注意到在發佈問題後我應該使用GET而不是POST。不幸的是它仍然不起作用。感謝您的鏈接,這真的很有幫助。 – user1152142