发布表单时,Ruby on Rails页面不会刷新 [英] Ruby on Rails page does not refresh when form is posted

查看:107
本文介绍了发布表单时,Ruby on Rails页面不会刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面发布的代码示例中,我试图允许页面的用户过滤出用户应显示哪些项目.我可以通过手动修改在地址栏中传递的参数来成功过滤结果.但是,当我单击页面上的筛选器"按钮时,它什么也没做.当按下按钮时,它将刷新页面并传递新的参数.有什么想法为什么会这样?我需要在控制器中添加任何内容吗?

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?

查看:

= 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

单击提交"按钮后,控制台中没有任何反应,或者浏览器似乎无任何作用. 导轨3.2.14 Ubuntu 12.04 LTS

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

推荐答案

代码已使用适当的缩进进行了固定:

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"

这篇关于发布表单时,Ruby on Rails页面不会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆