草庐IT

Model1Serializer

全部标签

ruby - LoadError : Expected {app_path}/models/model file. rb 定义模型名称

运行时出现错误LoadError:Expected/home/user/Desktop/Tripurari/myapp/app/models/host.rbtodefineHost##但它上面的每样东西都各就各位。有人能告诉我方法下面的确切问题是什么吗?defself.check_all(keyword)memo_mutex=Mutex.newmemo={}threads=[]name=keyword.keywordSITES.eachdo|site_and_options|threads 最佳答案 问题可能是由自动加载器引起的。如

ruby-on-rails - 在 Nested Model Form Rails 4 中删除记录的问题

我正在关注RailsCast#196嵌套模型表单第1部分。我给了Controller和模型相同的名称,它都是属性。但是现在,当我尝试进行编辑并删除问题时。如果我选中复选框,它不会删除问题。像这样:型号:classSurvey:destroyaccepts_nested_attributes_for:questions,:reject_if=>lambda{|a|a[:content].blank?},:allow_destroy=>trueendclassQuestion调查控制员:classSurveysController查看文件prohibitedthissurveyfrombe

ruby-on-rails - rails : too many methods in model

TL;DR:我不知道如何组织我的逻辑域类。我有模型“应用程序”,这个模型是应用程序的“核心”,是我“进入”和操作其他模型的方式,例如:@application=Application.find(params[:application_id])@application.payment.update_attribute'active',true或unless@application.report.status或@application.set_income(params[:income][:new_income])所以模型Payment、Income和Report基本上是空的,因为我初始化

sql - Rails Model.find() 不返回信息(返回散列)

我正在使用Postgresql并且我不确定我在这里遗漏了什么,但是在我的数据库中调用了我的数据库helper.rb:defget_infoinfo=Scraper.find(1)putsinfoend在我的controller.rb中通过一个post请求,像这样:defcreatehelpers.get_infoend回来了#相对于我数据库中的实际信息:"subway"> 最佳答案 修改以下代码defget_infoinfo=Scraper.find(1)putsinfoend作为defget_infoScraper.find(1)

ruby-on-rails - 返回 : Validate Non-model fields in model file

我的表单中有一些不属于模型的字段,我知道如何在Controller中验证这些字段,但我想知道是否可以在模型中验证它?如果可能的话,接下来我将如何验证?例如text_field(nil,:non_model_field) 最佳答案 试试这个:在模型中放置一个虚拟属性。classMyModel 关于ruby-on-rails-返回:ValidateNon-modelfieldsinmodelfile,我们在StackOverflow上找到一个类似的问题: http

ruby-on-rails - JSONAPI 资源 : serialize a namespaced model

我正在尝试使用JSONAPIResources在Rails引擎中,我定义了DokiCore::Tenant(模型)在doki_core/app/models/tenant.rb和DokiCore::TenantResource在doki_core/app/resources/tenant_resource.rb中。当我尝试序列化为哈希时,遇到以下错误:NoMethodError:undefinedmethodtenant_path'for#from/Users/typeoneerror/.rvm/gems/ruby-2.2.2@doki/gems/jsonapi-resources-0

ruby-on-rails - NilClass :Class (Using formtastic in Rails 3. 0.3,Ruby 1.9.2 的未定义方法 `model_name')

对于为什么这不起作用有点困惑。我在Windows7上使用Ruby1.9.2和Rails3.0.3。尝试使用formtastic为后期模型制作表单,但是,当我尝试呈现View时,我不断收到undefinedmethod`model_name'forNilClass:Class。相关代码:Demonly_controller.rbclassDemonlyControllerPosts_controller.rbclassPostsControllerPost.rbclassPostIndex.html.erbDemonly很可能我正在做一些非常愚蠢的事情,因为我生病了并且精神不振。提取的源

ruby-on-rails - 在 Rails 中使用 ActiveModel::Serializer - JSON 数据在 json 和索引响应之间不同

我正在使用active_model_serializersgem来控制序列化数据,并看到一些奇怪的行为。我的代码如下所示:模型和序列化器classUserincludeMongoid::Documentfield:first_name,:type=>Stringfield:last_name,:type=>Stringdeffull_namefirst_name+""+last_nameendendclassUserSerializerControllerclassUsersControllerView(app/views/users/index.html.erb)...$(funct

ruby-on-rails - 未定义方法 `[]' 为 nil :NilClass for Rails model on new

我有一个模型学生和一个Controller学生。在Controller中我有一个新方法defnew@student=Student.newend然后我有一个/views/students/new.html.haml,它通过使用@student变得异常。我得到错误undefinedmethod`[]'fornil:NilClass这是它的火腿%h1Students#new%pFindmeinapp/views/students/new.html.haml=form_for(@student)do|f|=f.text_field:email=f.button"Submit"如果我用Stud

ruby-on-rails - 多个 model.save's in 1 if condition with an unless

我正在尝试保存一个response并保存一个issue如果它在一种情况下不是nil所以我没有多个if/else条件使此逻辑复杂化。对于@response存在且issue为nil的用例,这不会进入ifblock。是否有明显的东西我没有看到,或者我不能像这样在一行中写下我的逻辑?注意:我知道应该使用事务,但我现在只是想建立一个工作原型(prototype)。if@response.save&&(issue.saveunlessissue.nil?)#Doesnotgetintotheifblockwhen@responseexistsandissueisnilp'insave'format