Use “error_messages” in Rails 3.2? (raises “undefined method” error)
I am getting the following error in my Rails 3.2 functional tests:
ActionView::Template::Error: undefined method `error_messages' for # <ActionView::Helpers::FormBuilder:0x007ff8ad00d3b0>
The view code that is creating the error:
<%= form_for [@camp,@program]do|f|%><%= f.error_messages %># problematic code<%= f.label :name %><%end%>
Here is the code in my controller that is calling the above view code:
render :action =>"edit",:status =>:bad_request
And here is the test I am running:
test "update a program with a bad request"do
put :update,:id => programs(:traditional).to_param,:program =>{:min_age =>"a"},:camp_id => camps(123).uri
assert_response :bad_request
end
正确解决方法: <%= form_for [@camp,@program]do|f|%><%@program.errors.full_messages.each do|msg|%><p><%= msg %></p><%end%><%= f.label :name %><%end%>
参考路径:http://stackoverflow.com/questions/10002140/use-error-messages-in-rails-3-2-raises-undefined-method-error
Use “error_messages” in Rails 3.2? (raises “undefined method” error)的更多相关文章
- rails undefined method error_messages
rails undefined method error_messages 学习了:http://stackoverflow.com/questions/10002140/use-error-mess ...
- undefined method `environment' for nil:NilClass when importing Bootstrap into rails
今天做项目时往Gemfile里加了各gem, 然后bundle update了一下, 然后悲剧了,出现了undefined method `environment' for nil:NilClass ...
- rails中render 和 redirect_to的区别, each只能用在数组中,如果只有一个或者零个项,用each方法会报错undefined method `each' for #...
在render中,即使有:action,那么也仅仅是取对应的view中的模板(html.erb)而已,所以这里即使浏览器中的url是/orders/xcreate,但是显示的界面是/app/views ...
- ruby on rails错误undefined method `title' for nil:NilClass
首先搞清楚这句话,在 Ruby 中,方法分为 public.private 和 protected 三种,仅仅有 public 方法才干作为控制器的动作. 我的出错的代码例如以下: controlle ...
- 开源IDS系列--snorby 2.6.2 undefined method `run_daily_report' for Event:Class (NoMethodError)
rails runner "Event.run_daily_report"测试邮件配置undefined method `run_daily_report' for Event:C ...
- Xcode同一个Workspace中两个工程依赖于Undefined Symbol Error
Workspace中包含两个工程A和B: A是dylib工程,引用了另一个动态库C,B需要链接(依赖)A库.当编译B时,会先编译A,然后把A生成的dylib拷贝到B的生成目录中.如果要运行B的话需要把 ...
- "undefined method `root' for nil:NilClass" error when using "pod install" 解决办法
如果pod undate 的时候报错"undefined method `root' for nil:NilClass" error when using "pod in ...
- gitlab ActionView::Template::Error (undefined method `[]' for nil:NilClass): 500错误
Started GET "/mygroup/myproject/tree/master/MyDirectory" for 127.0.0.1 at 2014-10-22 22:42 ...
- thinkphp报错Call to undefined method app\index\controller\Index::fetch()
因为要写一个系统,所以又重新下载了thinkphp,然后安装了一下.回忆起这个问题很容易让新手朋友费解.会出现如下报错:Call to undefined method app\index\contr ...
随机推荐
- javascript 常用api
常用API合集 来源于:https://www.kancloud.cn/dennis/tgjavascript/241852 一.节点 1.1 节点属性 Node.nodeName //返回节点名称, ...
- APIJSON,让接口和文档见鬼去吧!
我: APIJSON,让接口和文档见鬼去吧! https://github.com/TommyLemon/APIJSON 服务端: 什么鬼? 客户端: APIJSON是啥? 我: APIJSON是一种 ...
- apicloud上传图片
//定义api $("#photo").change(function(){ //获取图片 api.getPicture({ sourceType: 'library', enco ...
- spring init
DN学院讲师招募 Markdown编辑器轻松写博文 TOP 50 CTO坐镇直招 读文章说感想获好礼 通过Spring @PostConstruct 和 @PreDestroy ...
- Java面试07|Redis数据库
1.Redis持久化的几种方式 (1)RDB(Redis DataBase)持久化 (2)AOF(Append Only File)持久化 2.Redis的缓存失效策略 主要涉及到expire对主键过 ...
- Asp.net MVC 视图使用像Ajax,ViewBag提示为找到上下文
不知是什么原因,所有的视图中Ajax,ViewBag之类的都提示为找到上下文(由于换了个版本Vs,猜测应该是Vs的原因),然后顺利在网上找到了解决方案. 给地址链接:https://social.ms ...
- Spring IOC容器中Bean的生命周期
1.IOC容器中Bean的生命周期 构造器函数 设置属性 初始化函数(在Bean配置中 init-method) 使用Bean 结束时关闭容器(在Bean中配置destroy-method) 2.Be ...
- [lua] mac上如何编译snapshot(检测Lua中的内存泄露)
最近我们的unity手游频繁闪退,只要进入战斗场景,之后一段时间就会闪退,如果是在unity编辑器中则会报出not enough memory的错误!猜测应该是有内存泄漏: 由于我们使用了tolua, ...
- python 机器学习 K-近邻算法
本人想边写文章,边学习,用的是 网上最火的<机器学习实战>machine learning in action 来做一次实践. 希望在过程中理顺思路之余,也有分享自己的一些理解,学习.加油 ...
- django generic view - ListView
ListView (带分页) 1.带分页效果的基础模板 1) view from django.views.generic.list import ListView from employ.model ...