所有表单都没有传递参数

时间:2011-09-27 10:48:05

标签: ruby-on-rails ruby-on-rails-3

我的rails应用程序中的所有表单都没有提交参数甚至是production.log:

Started GET "/countries/afghanistan/edit/" for 41.132.43.55 at Tue Sep 27 03:39:06 -0700 2011
  Processing by CountriesController#edit as HTML
  Parameters: {"id"=>"afghanistan"}
Rendered countries/_form.html.erb (80.2ms)
Rendered application/_nav.html.erb (2.8ms)
Rendered countries/edit.html.erb within layouts/application (85.2ms)
Completed 200 OK in 87ms (Views: 85.6ms | ActiveRecord: 0.5ms)


Started GET "/countries/afghanistan/" for 41.132.43.55 at Tue Sep 27 03:40:20 -0700 2011
  Processing by CountriesController#show as HTML
  Parameters: {"id"=>"afghanistan"}
Rendered application/_nav.html.erb (3.9ms)
Rendered countries/show.html.erb within layouts/application (16.7ms)
Completed 200 OK in 21ms (Views: 15.3ms | ActiveRecord: 2.3ms)

这是来自编辑操作,然后提交表单直接进入show动作。在我的开发检查器中,它显示POST请求已永久移动(301)到GET请求:

enter image description here

我不确定在这一点上是什么。一切在开发中都很好,但在生产中却没有。这是我的production.rb

App::Application.configure do
  config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.action_dispatch.x_sendfile_header = "X-Sendfile"
  config.serve_static_assets = false
  config.i18n.fallbacks = true

  config.active_support.deprecation = :notify
  ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :user_name            => "***@***.com",
    :password             => "***",
    :authentication       => "plain",
    :enable_starttls_auto => true
  }
  config.middleware.use ExceptionNotifier,
    :email_prefix => "[Exception] ",
    :sender_address => %{"Exception Notifier" <***@***.com>},
    :exception_recipients => %w{***@***.com}
end

非常感谢任何帮助。谢谢!

更新1 这是会议#new

<%= form_tag sessions_path do %>
  <p>
    <%= label_tag :login, "Email Address" %><br />
    <%= text_field_tag :login, params[:login] %>
  </p>
  <p>
    <%= label_tag :password %><br />
    <%= password_field_tag :password %>
  </p>
  <p><%= submit_tag "Log in" %></p>
<% end %>

这是另一种形式:

<%= form_for @satellite do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <% for country in Country.find(:all) %>
      <%= check_box_tag "satellite[country_ids][]", country.id, @satellite.countries.include?(country) %>
      <%= label_tag "satellite[country_ids][]", country.name, :for => "satellite[country_ids][]" %><br />
    <% end %>
  </p>
  <p><%= f.submit %></p>
<% end %>

但就像我说的那样,没有一种形式传递参数。

更新2 这是路线:

  edit_current_user        /user/edit(.:format)                             {:controller=>"users", :action=>"edit"}
             signup        /signup(.:format)                                {:controller=>"users", :action=>"new"}
             logout        /logout(.:format)                                {:controller=>"sessions", :action=>"destroy"}
              login        /login(.:format)                                 {:controller=>"sessions", :action=>"new"}
           sessions GET    /sessions(.:format)                              {:controller=>"sessions", :action=>"index"}
                    POST   /sessions(.:format)                              {:controller=>"sessions", :action=>"create"}
        new_session GET    /sessions/new(.:format)                          {:controller=>"sessions", :action=>"new"}
       edit_session GET    /sessions/:id/edit(.:format)                     {:controller=>"sessions", :action=>"edit"}
            session GET    /sessions/:id(.:format)                          {:controller=>"sessions", :action=>"show"}
                    PUT    /sessions/:id(.:format)                          {:controller=>"sessions", :action=>"update"}
                    DELETE /sessions/:id(.:format)                          {:controller=>"sessions", :action=>"destroy"}
              users GET    /users(.:format)                                 {:controller=>"users", :action=>"index"}
                    POST   /users(.:format)                                 {:controller=>"users", :action=>"create"}
           new_user GET    /users/new(.:format)                             {:controller=>"users", :action=>"new"}
          edit_user GET    /users/:id/edit(.:format)                        {:controller=>"users", :action=>"edit"}
               user GET    /users/:id(.:format)                             {:controller=>"users", :action=>"show"}
                    PUT    /users/:id(.:format)                             {:controller=>"users", :action=>"update"}
                    DELETE /users/:id(.:format)                             {:controller=>"users", :action=>"destroy"}
               maps GET    /maps(.:format)                                  {:controller=>"maps", :action=>"index"}
                    POST   /maps(.:format)                                  {:controller=>"maps", :action=>"create"}
            new_map GET    /maps/new(.:format)                              {:controller=>"maps", :action=>"new"}
           edit_map GET    /maps/:id/edit(.:format)                         {:controller=>"maps", :action=>"edit"}
                map GET    /maps/:id(.:format)                              {:controller=>"maps", :action=>"show"}
                    PUT    /maps/:id(.:format)                              {:controller=>"maps", :action=>"update"}
                    DELETE /maps/:id(.:format)                              {:controller=>"maps", :action=>"destroy"}
   country_channels GET    /countries/:country_id/channels(.:format)        {:controller=>"channels", :action=>"index"}
    country_channel GET    /countries/:country_id/channels/:id(.:format)    {:controller=>"channels", :action=>"show"}
 country_satellites GET    /countries/:country_id/satellites(.:format)      {:controller=>"satellites", :action=>"index"}
  country_satellite GET    /countries/:country_id/satellites/:id(.:format)  {:controller=>"satellites", :action=>"show"}
country_testimonies GET    /countries/:country_id/testimonies(.:format)     {:controller=>"testimonies", :action=>"index"}
  country_testimony GET    /countries/:country_id/testimonies/:id(.:format) {:controller=>"testimonies", :action=>"show"}
 country_statistics GET    /countries/:country_id/statistics(.:format)      {:controller=>"statistics", :action=>"index"}
  country_statistic GET    /countries/:country_id/statistics/:id(.:format)  {:controller=>"statistics", :action=>"show"}
     country_videos GET    /countries/:country_id/videos(.:format)          {:controller=>"videos", :action=>"index"}
      country_video GET    /countries/:country_id/videos/:id(.:format)      {:controller=>"videos", :action=>"show"}
 country_challenges GET    /countries/:country_id/challenges(.:format)      {:controller=>"challenges", :action=>"index"}
  country_challenge GET    /countries/:country_id/challenges/:id(.:format)  {:controller=>"challenges", :action=>"show"}
          countries GET    /countries(.:format)                             {:controller=>"countries", :action=>"index"}
                    POST   /countries(.:format)                             {:controller=>"countries", :action=>"create"}
        new_country GET    /countries/new(.:format)                         {:controller=>"countries", :action=>"new"}
       edit_country GET    /countries/:id/edit(.:format)                    {:controller=>"countries", :action=>"edit"}
            country GET    /countries/:id(.:format)                         {:controller=>"countries", :action=>"show"}
                    PUT    /countries/:id(.:format)                         {:controller=>"countries", :action=>"update"}
                    DELETE /countries/:id(.:format)                         {:controller=>"countries", :action=>"destroy"}
           channels GET    /channels(.:format)                              {:controller=>"channels", :action=>"index"}
                    POST   /channels(.:format)                              {:controller=>"channels", :action=>"create"}
        new_channel GET    /channels/new(.:format)                          {:controller=>"channels", :action=>"new"}
       edit_channel GET    /channels/:id/edit(.:format)                     {:controller=>"channels", :action=>"edit"}
            channel GET    /channels/:id(.:format)                          {:controller=>"channels", :action=>"show"}
                    PUT    /channels/:id(.:format)                          {:controller=>"channels", :action=>"update"}
                    DELETE /channels/:id(.:format)                          {:controller=>"channels", :action=>"destroy"}
         satellites GET    /satellites(.:format)                            {:controller=>"satellites", :action=>"index"}
                    POST   /satellites(.:format)                            {:controller=>"satellites", :action=>"create"}
      new_satellite GET    /satellites/new(.:format)                        {:controller=>"satellites", :action=>"new"}
     edit_satellite GET    /satellites/:id/edit(.:format)                   {:controller=>"satellites", :action=>"edit"}
          satellite GET    /satellites/:id(.:format)                        {:controller=>"satellites", :action=>"show"}
                    PUT    /satellites/:id(.:format)                        {:controller=>"satellites", :action=>"update"}
                    DELETE /satellites/:id(.:format)                        {:controller=>"satellites", :action=>"destroy"}
        testimonies GET    /testimonies(.:format)                           {:controller=>"testimonies", :action=>"index"}
                    POST   /testimonies(.:format)                           {:controller=>"testimonies", :action=>"create"}
      new_testimony GET    /testimonies/new(.:format)                       {:controller=>"testimonies", :action=>"new"}
     edit_testimony GET    /testimonies/:id/edit(.:format)                  {:controller=>"testimonies", :action=>"edit"}
          testimony GET    /testimonies/:id(.:format)                       {:controller=>"testimonies", :action=>"show"}
                    PUT    /testimonies/:id(.:format)                       {:controller=>"testimonies", :action=>"update"}
                    DELETE /testimonies/:id(.:format)                       {:controller=>"testimonies", :action=>"destroy"}
         statistics GET    /statistics(.:format)                            {:controller=>"statistics", :action=>"index"}
                    POST   /statistics(.:format)                            {:controller=>"statistics", :action=>"create"}
      new_statistic GET    /statistics/new(.:format)                        {:controller=>"statistics", :action=>"new"}
     edit_statistic GET    /statistics/:id/edit(.:format)                   {:controller=>"statistics", :action=>"edit"}
          statistic GET    /statistics/:id(.:format)                        {:controller=>"statistics", :action=>"show"}
                    PUT    /statistics/:id(.:format)                        {:controller=>"statistics", :action=>"update"}
                    DELETE /statistics/:id(.:format)                        {:controller=>"statistics", :action=>"destroy"}
             videos GET    /videos(.:format)                                {:controller=>"videos", :action=>"index"}
                    POST   /videos(.:format)                                {:controller=>"videos", :action=>"create"}
          new_video GET    /videos/new(.:format)                            {:controller=>"videos", :action=>"new"}
         edit_video GET    /videos/:id/edit(.:format)                       {:controller=>"videos", :action=>"edit"}
              video GET    /videos/:id(.:format)                            {:controller=>"videos", :action=>"show"}
                    PUT    /videos/:id(.:format)                            {:controller=>"videos", :action=>"update"}
                    DELETE /videos/:id(.:format)                            {:controller=>"videos", :action=>"destroy"}
         challenges GET    /challenges(.:format)                            {:controller=>"challenges", :action=>"index"}
                    POST   /challenges(.:format)                            {:controller=>"challenges", :action=>"create"}
      new_challenge GET    /challenges/new(.:format)                        {:controller=>"challenges", :action=>"new"}
     edit_challenge GET    /challenges/:id/edit(.:format)                   {:controller=>"challenges", :action=>"edit"}
          challenge GET    /challenges/:id(.:format)                        {:controller=>"challenges", :action=>"show"}
                    PUT    /challenges/:id(.:format)                        {:controller=>"challenges", :action=>"update"}
                    DELETE /challenges/:id(.:format)                        {:controller=>"challenges", :action=>"destroy"}
       all_channels        /all/channels(.:format)                          {:controller=>"channels", :action=>"all"}
     all_satellites        /all/satellites(.:format)                        {:controller=>"satellites", :action=>"all"}
    all_testimonies        /all/testimonies(.:format)                       {:controller=>"testimonies", :action=>"all"}
     all_statistics        /all/statistics(.:format)                        {:controller=>"statistics", :action=>"all"}
         all_videos        /all/videos(.:format)                            {:controller=>"videos", :action=>"all"}
     all_challenges        /all/challenges(.:format)                        {:controller=>"challenges", :action=>"all"}
               root        /(.:format)                                      {:controller=>"countries", :action=>"map"}
               home        /home(.:format)                                  {:controller=>"countries", :action=>"map"}

1 个答案:

答案 0 :(得分:0)

有一件事,我前一段时间遇到了非数字id,是resources路线上的默认约束。覆盖这些约束解决了问题,但这也应该是开发模式中的问题。无论如何,你可以尝试

resources :countries, :constraints => { :id => /.*/ }

加上你的嵌套路线