草庐IT

accept-charset

全部标签

ruby-on-rails - 在 Rails 中使用 accepts_nested_attributes_for + 批量赋值保护

假设你有这个结构:classHouse请注意,Tv的用户是故意不可访问的。所以你有一个三层嵌套的表单,允许你在一个页面上输入房子、房间和电视。这是Controller的创建方法:defcreate@house=House.new(params[:house])if@house.save#...standardstuffelse#...standardstuffendend问题:您究竟如何为每台电视填充user_id(它应该来自current_user.id)?什么是好的做法?这是我在其中看到的catch22。将user_ids直接填充到params散列中(它们嵌套得很深)保存将失败,因

ruby-on-rails - 尝试使用 accepts_nested_attributes_for 和 has_and_belongs_to_many 但未填充连接表

我正在学习RoR并尝试使用accepts_nested_attributes_for和has_and_belongs_to_many来提交传统上为两种形式的信息。我在一些网站上看到它们兼容,一些网站不兼容,还有一些网站不知道。作为引用,我使用的是Rails2.3.4。我尝试根据nestedmodels上的Ryan'sScraps教程对我的解决方案进行建模从我尝试调试的内容来看,我似乎有两个问题,但我不确定为什么。当我提交包含嵌套模型的表单时,只发布了部分嵌套模型信息。我只得到第一个字段,而不是用户可能选择的“n”个其他字段在发布的单个字段中,没有任何行插入到我为HABTM关系创建的连接

ruby-on-rails - accepts_nested_attributes_for 忽略空白值

我有classProfilehas_many:favorite_books,:dependent=>:destroyhas_many:favorite_quotes,:dependent=>:destroyaccepts_nested_attributes_for:favorite_books,:allow_destroy=>trueaccepts_nested_attributes_for:favorite_quotes,:allow_destroy=>trueend我有一个动态表单,您可以在其中按“+”添加新的文本区域以创建新的收藏夹。我想要做的是忽略空白的,我发现这比非嵌套属性更

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

jquery - Rails accepts_nested_attributes_for 与 f.fields_for 和 AJAX

我很好奇如何正确使用accepts_nested_attributes_for和f.fields_for。views/orders/new.html.erbDetailsviews/order_details/_details.html.erb$$$→|length:|width:|height:|weight:controllers/orders_controller.rb(我很确定这是错误的......非常感谢这里的任何帮助)defcreate@order=Order.create(params[:order])if@order.saveflash[:success]=

ruby-on-rails - 未定义方法 `accept' 为 nil :NilClass on rake db:migrate

使用ruby​​-1.9.2和rails3.2.1。mysql2的版本是0.2.7。运行rakedb:migrate时出现错误:“nil:NilClass的未定义方法‘accept’:”跟踪包括:gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in`to_sql' 最佳答案 从以下位置更改您的Gemfile:gem'activerecord-mysql2-adapter'到:gem'mysq

ruby-on-rails - accepts_nested_attributes_for的替代方法-也许是virtus

我对rails比较陌生,最终找到了正确的使用accepts_nested_attributes_for的方法。然而,网络上有一些严肃的资源说,使用accepts_nested_attributes_for通常是一种不好的做法(比如这个one)。要避免accepts_nested_attributes_for需要做哪些更改,以及将附加类文件放在哪个文件夹中(我想需要一个附加类)。我读到virtus适合这个。对吗?下面是一个仍然使用accepts_nested_attributes_for的非常基本的示例(查找完整的示例here):模型classPerson控制器classPeopleCo

ruby-on-rails - 获取 fields_for 和 accepts_nested_attributes_for 以处理 belongs_to 关系

我似乎无法使用Rails2.3的新accepts_nested_attributes_for工具在RailsView中为belongs_to关系生成嵌套表单。我确实检查了许多可用的资源,看起来我的代码应该可以工作,但是fields_for对我来说是爆炸性的,我怀疑它与如何做有关我配置了嵌套模型。我遇到的错误是一个常见的错误,可能有多种原因:'@account[owner]'isnotallowedasaninstancevariablename下面是涉及的两个模型:classAccount'User',:foreign_key=>'owner_id'accepts_nested_att

ruby-on-rails - accepts_nested_attributes_for rails 4 没有删除

我已经阅读和研究了大约3天。这是我最后的选择。土地.rb:has_many:uploads,:dependent=>:destroyaccepts_nested_attributes_for:uploads,:allow_destroy=>true,:reject_if=>:all_blank上传.rbbelongs_to:land_land_form_partial.html.erb{:multipart=>true}do|f|%>Delete:#...buttonsandotherfieldslands_controller.rbdefupdateif@land.update_at

ruby-on-rails - accepts_nested_attributes_for 和 belongs_to 多态

我想用accepts_nested_attributes_for建立一个多态关系。这是代码:classContact:clientendclassJob:trueaccepts_nested_attributes_for:clientend当我尝试访问Job.create(...,:client_attributes=>{...}时给我NameError:uninitializedconstantJob::Client 最佳答案 我也遇到了“ArgumentError:无法构建关联模型名称。您是否正在尝试构建多态一对一关联?”的问题