简体   繁体   中英

Formtastic remote form

I am using Formtastic and I am trying to set up a remote form to access the edit action without leaving the current page and going to the /1/edit type url.

My form is as follows:

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

The view is located under shipdr/dash/websites, the controller for the dash view does not have an edit action so I need to use the remote form to access the edit method of a different controller.

The form displays and the page loads without displaying any errors, however, when I click on the 'Create Website' button nothing is happening. If I remove the remote => true part of line 1 then I get No route matches [POST] "/shipdr/websites/14/edit" when I click on the button.

Here are my routes using rake routes:

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

Any help figuring this out would be appreciated.

Have you checked your routes.rb file? Give us the rake routes info

Is your controller setup for ajax requests?

Do you have the necessary javascript that acts upon the semantic form?

These are things to look into to get your form working.

Check out https://gist.github.com/548387?file=tickets_controller.rb to get an idea of hwat you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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