rails 3 undefined method `model_name' for ActiveRecord::Relation:Class.
发布日期:2021-09-29 20:08:57
浏览次数:24
分类:技术文章
本文共 1971 字,大约阅读时间需要 6 分钟。
rails 3 form_for 的问题 undefined method `model_name' for ActiveRecord::Relation:Class.def edit @office = Office.where("id = ? AND company_id = ?", params[:id], @company.id ) end
<%= simple_form_for @office, :url => settings_office_path, :html => { :class => "office_form" } do |f| %>需要修改Edit <%= @office.office_name %> Details
<%= render :partial => 'form', :locals => { :f => f } %> <% end %>
@office = Office.where(:company_id => @company.id).find(params[:id]) @office = @company.offices.find(params[:id])下面有个人和我类似
class Event < ActiveRecord::Base belongs_to :user attr_accessible :event_name, :Starts_at, :finish, :tracks end
class User < ActiveRecord::Base has_many :events, :dependent => :destroy attr_accessible :name, :event_attributes accepts_nested_attributes_for :events, :allow_destroy => true end
ActiveRecord::Schema.define(:version => 20101201180355) do create_table "events", :force => true do |t| t.string "event_name" t.string "tracks" t.datetime "starts_at" t.datetime "finish" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" end end[quote] NoMethodError in Users#index undefined method `events' for #<ActiveRecord::Relation:0x4177518> Extracted source (around line #10): 7: <th><%= sortable "Tracks" %></th> 8: </tr> 10: <% @users.events.each do |event| %> 11: <% debugger %> 12: <tr> 13: <td><%= event.starts_at %></td> Trace of template inclusion: app/views/users/index.html.erb Rails.root: C:/rails_project1/events_manager Application Trace | Framework Trace | Full Trace app/views/users/_event_user.html.erb:10:in `_app_views_users__event_user_html_erb__412443848_34308540_1390678' app/views/users/index.html.erb:7:in `_app_views_users_index_html_erb___603337143_34316016_0' [/quote] 问题解决:
@users = User.find() #要变成 @users = User.where( ).all #或者如下 @users = User.where(:admin => true).where('created_at > ?', min_date).order('created_at').limit(10).all
转载地址:https://blog.csdn.net/horace_lee/article/details/83942962 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月10日 10时25分51秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
计算CP、CR、CF1、OP、OR、OF1和mAP的top-3评价指标
2019-04-28
python将嵌套数组转为单层数组
2019-04-28
pytorch打印自定义网络的每层的名称
2019-04-28
解决ubantu只能读取U盘文件,不能将文件复制到U盘里面
2019-04-28
MS-COCO2014数据集标签互译
2019-04-28
MacBook Pro快捷键总结
2019-04-28
解决mac里面打开控制台提示 您需要安装JDK才能使用"java"命令行工具
2019-04-28
reactos操作系统实现(92)
2019-04-28
reactos操作系统实现(93)
2019-04-28
使用Python快速实现显示器关闭和锁住桌面
2019-04-28
reactos操作系统实现(94)
2019-04-28
reactos操作系统实现(95)
2019-04-28
reactos操作系统实现(96)
2019-04-28
reactos操作系统实现(97)
2019-04-28
reactos操作系统实现(98)
2019-04-28