`
glacier3
  • 浏览: 377392 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

rails cancan AssociationTypeMismatch

阅读更多
ActiveRecord::AssociationTypeMismatch (User(#70244306330580) expected, got String(#70244198919200)):
  activerecord (3.2.13) lib/active_record/associations/association.rb:204:in `raise_on_type_mismatch'
  activerecord (3.2.13) lib/active_record/associations/belongs_to_association.rb:6:in `replace'
  activerecord (3.2.13) lib/active_record/associations/singular_association.rb:17:in `writer'
  activerecord (3.2.13) lib/active_record/associations/builder/association.rb:51:in `block in define_writers'
  activerecord (3.2.13) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
  activerecord (3.2.13) lib/active_record/attribute_assignment.rb:78:in `each'
  activerecord (3.2.13) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
  activerecord (3.2.13) lib/active_record/base.rb:498:in `initialize'
  state_machine (1.2.0) lib/state_machine/integrations/active_record.rb:470:in `initialize'


如果遇到这个问题,那么请检查请求parameters里面是不是有一个Key-Value为"id": "",  如果有,请去掉。我这里用了cancan,配置了安全验证后,每个action都会去首先去取id为params[:id]的User。

代码:https://github.com/josevalim/inherited_resources/blob/master/lib/inherited_resources/base_helpers.rb#L51
def resource
        get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_find, params[:id]))
      end
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    Rails3 device and cancan

    ROR ruby on rails device plugin教程

    ruby gems (rails ,padrino, cancan ,puppet)

    ruby gems (rails ,padrino, cancan ,puppet)

    CanCan1Ruby2Devise3Rails4:在 Rails 4 上使用 CanCan 1 和 Devise 3 的应用程序

    ##设置 CanCan 1:Ruby 2:设计 3:Rails 4本指南部分是根据 Tony Amoyal 的教程 [here.] ( ) 创建的######创建一个新应用程序: rails new appbundle install ######安装设计: gem 'devise'bundle install rails ...

    cancan:Ruby on Rails的授权宝石

    CanCan是Ruby on Rails的授权库,它限制了给定用户被允许访问的资源。 所有权限都在一个位置( Ability类)中定义,并且不会在控制器,视图和数据库查询之间重复。 安装 在Rails 3中,将其添加到您的Gemfile并运行...

    rails 2.3.2离线安装rails 2.3.2离线安装

    rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...

    [Rails] Crafting Rails Applications (英文版)

    [Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Rails之道,完整扫描版

    《Rails之道》按照Rails的各个子系统进行组织编排,分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器、页面生成和路由,REST、资源和Rails,ActiveRecord的基础、关联、验证和高级技巧,...

    Ruby on Rails Tutorial

    《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...

    rails敏捷开发的购物车系统

    本资源是参照rails敏捷开发第四版书中的例子,rails的版本是rails3.2.6

    Rails项目源代码

    一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码

    Bootstrap for Rails (2015)

    Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...

    adminlte-rails, AdminLTE Rails gem 将AdminLTE主题与 Rails 资产管道集成.zip

    adminlte-rails, AdminLTE Rails gem 将AdminLTE主题与 Rails 资产管道集成 AdminLTE Rails gem AdminLTE 是后端的高级 Bootstrap 主题。英镑 AdminLTE Rails gem 与 Rails 资产管道集成了英镑AdminLTE主题。安装将...

    Agile Web Development with Rails 4

    Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...

    提升Ruby on Rails性能的几个解决方案

    Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...

    使用Aptana+Rails开发Rails Web应用(中文)

    使用Aptana+Rails开发Rails Web应用 有Aptana的安装配置等等,中文

    [Michael Hartl] Ruby on Rails Tutorial

    Learn Web Development with Rails Clear EPUB version in English, Second Edition “The author is clearly an expert at the Ruby language and the Rails framework, but more than that, he is a working ...

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    With this fully revised new edition, take a holistic view of full-stack development to create usable, high-performing applications with Rails 5. Rails is a great tool for building web applications, ...

Global site tag (gtag.js) - Google Analytics