Tag: undefined

ActiveRecord :: Relation(嵌套属性)的未定义方法

结果:: ActiveRecord_Relation的未定义方法`results’:0x007f9ee69ad148> Quantifieds#指数 这里的第一行是导致exception的原因。 要重述这个问题,我如何定义date_value和result_value以使其在quantieds索引中起作用? 它们来源于:_form中的结果。 我正在使用cocoon来创建嵌套属性。 整个索引 (根据第一个答复响应更新) AVERAGE () INSTANCE () <span class="glyphicon glyphicon-plus" result %> [:month, :year], class: ‘date-select’ %> 我需要更改控制器中的任何内容吗? class QuantifiedsController < ApplicationController before_action :set_quantified, only: [:show, :edit, :update, :destroy] before_action :authenticate_user!, except: [:index, :show] def index @quantifieds = Quantified.joins(:results).all @averaged_quantifieds = current_user.quantifieds.averaged @instance_quantifieds = current_user.quantifieds.instance end def show end […]

为什么我得到错误nil的未定义方法`name’:使用Ruby on Rails的NilClass?

我认为名称和电子邮件等方法在rails中是默认的吗? 在我的静态页面视图中,在profile.html.erb中,我有: 我输入了static_page_controller def profile @user = User.find_by_remember_token(:remember_token) end 当我转到控制台User.find_by_remember_token(“actualtoken”)。name返回适当的用户名,但是:remember_token没有。 我如何制作:remember_token =登录用户记住令牌? 在我的sessions_helper中,我有 def log_in(user) cookies.permanent[:remember_token] = user.remember_token current_user = user end def logged_in? !current_user.nil? end def current_user=(user) @current_user = user end def current_user @current_user ||= user_from_remember_token end def log_out current_user = nil cookies.delete(:remember_token) end private def user_from_remember_token remember_token = cookies[:remember_token] User.find_by_remember_token(remember_token) unless remember_token.nil? end […]

nil的未定义方法’map’:NilClass

当用户试图更新他们的个人资料时,我的应用程序似乎随机抛出一个“未定义的方法`map’为nil:NilClass”错误。 但奇怪的是,它说错误发生在更新上,但错误行实际上在视图中。 完整错误: users#update (ActionView::TemplateError) “undefined method `map’ for nil:NilClass” On line #52 of app/views/users/edit.html.erb Line 52: 以下是最近错误中的参数: {“user”=>{“email_notify”=>”email@example.com”, “network_id”=>””, “password_confirmation”=>”[FILTERED]”, “mobile”=>””, “password”=>”[FILTERED]”, “email”=>”email@example.com”}, “action”=>”update”, “_method”=>”put”, “id”=>”5089”, “controller”=>”users”} 老实说,不确定从哪里开始寻找。 我有一个用户说他可以从IE更新相同的信息,但不能从Firefox更新。 当我使用相同的信息时,我可以毫无问题地更新。 所以,我很难过。

如何在ActiveSupport的TimeZone类中设置时区

我试图将文本解析为使用ruby中的慢性日期。 但是,在尝试解析字符串时,我一直遇到错误。 错误: NoMethodError – undefined method ‘zone=’ for Time:Class: 这是代码: require ‘rubygems’ require ‘sinatra’ require ‘chronic’ require ‘date’ require ‘time’ require ‘active_support’ require ‘cgi’ require ‘json’ module TimeAPI ZoneOffset = { ‘A’ => +1, ‘ADT’ => -3, ‘AKDT’ => -8, ‘AKST’ => -9, ‘AST’ => -4, ‘B’ => +2, ‘BST’ => +1, ‘C’ => […]

用户编辑视图出现奇怪错误

当我在index视图中单击此链接时: 我收到此错误: NoMethodError in Users#edit Showing /rubyprograms/dreamstill/app/views/videos/_modal.html.erb where line #3 raised: undefined method `model_name’ for NilClass:Class Extracted source (around line #3): 1: 2: 3: 这与我在index视图中呈现的部分调用的_modal有关。 它有一个表格。 我的video控制器中也有这个: def index @video = Video.new @videos = Video.paginate(:page => params[:page], :per_page => 20) end 为什么我会收到此错误,我该如何解决? 更新: 这是我在Users控制器中的编辑操作: def edit @user = current_user end 这是_modal部分: prohibited this video from […]

如何修复level.rb使用:承诺的日子?

最初我有:committed日子工作得非常漂亮,但是在更改模型时,为了适应用户的检查能力,如果他错过了:committed一天我现在收到与以下代码相关的错误消息:committed : undefined method to_date for nil:NilClass Line#30 n_days = ((date_started.to_date)..Date.today).count { |date| committed_wdays.include? date.wday } n_days = ((date_started.to_date)..Date.today).count { |date| committed_wdays.include? date.wday } 此代码来自习惯模型: class Habit < ActiveRecord::Base belongs_to :user has_many :levels has_many :days, through: :levels #for being able to access Habit.find(*).days accepts_nested_attributes_for :levels, :days before_save :set_level acts_as_taggable serialize :committed, Array def evaluate(user) levels.each […]

为什么在Ruby中,|| 当`a`未定义时,1会抛出错误,但a = a || 1会不会?

当a未定义时,则为a || 1 a || 1将抛出错误,但a = a || 1 a = a || 1不会。 是不是有点不一致? irb(main):001:0> a NameError: undefined local variable or method ‘a’ for main:Object from (irb):1 from c:/ruby/bin/irb:12:in ” irb(main):002:0> a || 1 NameError: undefined local variable or method ‘a’ for main:Object from (irb):2 from c:/ruby/bin/irb:12:in ” irb(main):003:0> a = a || […]

我的ActiveRecord模型的未定义方法“has_attached_file”

我完全按照https://github.com/thoughtbot/paperclip上的文档在我的应用程序中安装工具回形针以进行图像上传。 我目前正在使用gem’paperclip’,’〜> 5.0.0.beta1’。 完成迁移后,四列已正确添加到我的架构中: t.string “picture_file_name” t.string “picture_content_type” t.integer “picture_file_size” t.datetime “picture_updated_at” 因此,我的回形针应该正确安装。 但是,当我继续将以下两行添加到我的模型类中时: has_attached_file :picture, styles: { medium: “300*300>”, thumb: “100*100” }, default_url: “/images/start_project3.jpg” validates_attachment_content_type :picture, content_type: /\Aimage\/.*\Z/ 一切都破了。 我尝试在rails控制台中创建,搜索或与模型类相关的任何内容,它对我大吼大叫,出现以下错误: NoMethodError: undefined method `has_attached_file’ for # 我已经尝试了多个版本的回形针,从早期版本4.3.0到最新版本的回形针,但问题仍然存在。 我还在更改和迁移之间重新启动了我的服务器,但这并没有解决问题。 这是我执行的迁移: class AddAttachmentPictureToProjects < ActiveRecord::Migration def self.up change_table :projects do |t| t.attachment :picture end end def […]