【发布时间】:2011-06-18 23:55:40
【问题描述】:
我在我的一个 Rails 视图中使用了 form_tag 来访问来自不同控制器的操作。这给我渲染错误消息带来了麻烦。我也在使用可能导致问题的 JQuery。我已经读过 form_tag 没有绑定到模型,所以这可能意味着像 validates_uniqueness_of 这样的东西可能不起作用。希望能帮助您理解 form_tag 的验证!
作为参考,这是我的控制器:
# 应用程序/控制器/posts_controller.rb 定义创建 @post = Post.new @post.text = 参数[:text] @post.user_id = current_user.id @post.save respond_to 做 |格式| 如果@post.save 格式.js format.html { redirect_to(username_path(:username => current_user)) } format.xml { 渲染 :xml => @post, :status => :created, :location => @post } 别的 format.html { 渲染 :action => "new" } format.xml { 渲染 :xml => @post.errors, :status => :unprocessable_entity } 结尾 结尾 结尾我的观点(在我的用户模型上)
# app/views/users/show.html "posts", :action => "create"}, :method => "post", :class=> 'newpost') %> 0, :class=> "submitadd") %> %lt;% 结束 %>【问题讨论】:
-
您遇到了什么问题?
-
服务器输出显示消息发布,但没有返回错误消息。当输入与验证匹配时,post 工作,当它没有在浏览器中发生任何事情时。