发布表单时,不会刷新Ruby on Rails页面

时间:2014-10-14 02:10:21

标签: ruby-on-rails ruby-on-rails-3.2 haml

在下面发布的代码示例中,我试图允许页面用户过滤掉用户应显示的项目。我可以通过手动修改地址栏中传递的参数来成功过滤结果。但是,当我单击页面上的“过滤器”按钮时,它什么都不做。当按下按钮时,它应该刷新页面并传递新参数。关于为什么会这样的想法?我是否需要在控制器中添加任何内容?

查看:

= form_tag projects_path, :method => :get do
  Include:
- @all_users.each do |user|
  = user
  = check_box_tag "users[#{user}]", 1, @all_users.include?(user), :id => "users_#{user}"
= submit_tag 'Filter', {:id => "users_submit"}

加载主页后的控制台:

[2014-10-13 23:32:55] INFO  WEBrick 1.3.1
[2014-10-13 23:32:55] INFO  ruby 1.9.3 (2013-06-27) [i686-linux]
[2014-10-13 23:32:55] INFO  WEBrick::HTTPServer#start: pid=2718 port=3000


Started GET "/projects" for 127.0.0.1 at 2014-10-13 23:32:58 -0300
Connecting to database specified by database.yml
Processing by ProjectsController#index as HTML
Project Load (0.2ms)  SELECT DISTINCT user FROM "projects" 
Redirected to http://localhost:3000/projects?users%5BCoulson%5D=1&users%5BFitz%5D=1&users%5BMay%5D=1&users%5BSimmons%5D=1&users%5BWard%5D=1
Project Load (0.2ms)  SELECT "projects".* FROM "projects" ORDER BY id
Completed 302 Found in 9ms (ActiveRecord: 0.4ms)


Started GET "/projects?users%5BCoulson%5D=1&users%5BFitz%5D=1&users%5BMay%5D=1&users%5BSimmons%5D=1&users%5BWard%5D=1" for 127.0.0.1 at 2014-10-13 23:32:59 -0300
Processing by ProjectsController#index as HTML
Parameters: {"users"=>{"Coulson"=>"1", "Fitz"=>"1", "May"=>"1", "Simmons"=>"1", "Ward"=>"1"}}
Project Load (0.2ms)  SELECT DISTINCT user FROM "projects" 
Project Load (0.2ms)  SELECT "projects".* FROM "projects" ORDER BY id
Rendered projects/index.html.haml within layouts/application (11.8ms)
Completed 200 OK in 61ms (Views: 59.3ms | ActiveRecord: 0.4ms)
[2014-10-13 23:32:59] WARN  Could not determine content-length of response body. Set  content-length of the response or set Response#chunked = true


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-10-13 23:32:59 -0300
Served asset /jquery.js - 304 Not Modified (5ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-10-13 23:32:59 -0300
Served asset /application.css - 304 Not Modified (1ms)
[2014-10-13 23:32:59] WARN  Could not determine content-length of response body. Set  content-length of the response or set Response#chunked = true
[2014-10-13 23:32:59] WARN  Could not determine content-length of response body. Set  content-length of the response or set Response#chunked = true


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-10-13 23:32:59 -0300
Served asset /application.js - 304 Not Modified (4ms)


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-10-13 23:32:59 -0300
Served asset /jquery_ujs.js - 304 Not Modified (1ms)

[2014-10-13 23:32:59] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

[2014-10-13 23:32:59] WARN  Could not determine content-length of response body. Set  content-length of the response or set Response#chunked = true

单击提交按钮后,控制台中没有任何操作,或者浏览器似乎做了什么。 Rails 3.2.14 Ubuntu 12.04 LTS

1 个答案:

答案 0 :(得分:0)

使用适当的缩进修复了代码:

= form_tag movies_path, :id => "ratings_form", :method => :get do
  Include: 
  - @all_ratings.each do |rating|
    = rating
    = check_box_tag "ratings[#{rating}]", 1, @ratings.include?(rating), :id => "ratings_#{rating}"
  = submit_tag "Refresh", :id => "ratings_submit"