Ruby on Rails page does not refresh when form is p

2019-09-18 02:41发布

In the code sample posted below, I am trying to allow the user of the page to filter out which projects should be displayed by user. I am able to successfully filter the results by manually modifying the parameters passed in the address bar. But when I click the Filter button on the page it does nothing at all. It should refresh the page with the new parameters being passed when the button is pressed. Any ideas as to why this happens? Do I need to add anything in my controller?

View:

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

Console After Loading Main Page:

[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

After clicking the submit button, nothing happens in the console, or does the browser seem to do anything. Rails 3.2.14 Ubuntu 12.04 LTS

1条回答
乱世女痞
2楼-- · 2019-09-18 03:20

Code was fixed with proper indentation:

= 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"
查看更多
登录 后发表回答