Tag: ruby

一个月Rails – 无效的电子邮件或密码

我花了大约一个星期的时间在“Mattan Griffel的一个月的路轨”上工作。 出于某种原因,当我返回时,密码或电子邮件对我的localhost:3000无效。 Mattan带领我们完成了使用email: user@example.com注册我们的localhost页面的过程email: user@example.com和password: foobar ,但它现在对我不起作用。 这可能是我在sublime中出现语法错误的错误,或者可能是什么问题? 这是终端在没有通过时读取的内容: Started POST “/users/sign_in” for 127.0.0.1 at 2013-06-06 13:53:44 -0600 Processing by Devise::SessionsController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”8rUKRPLsIttdHhv49tgT8KcvKbjT9mMP/lP5M/N8uPQ=”, “user”=>{“email”=>”user@example.com”, “password”=>”[FILTERED]”, “remember_me”=>”0”}, “commit”=>”Sign in”} User Load (0.3ms) SELECT “users”.* FROM “users” WHERE “users”.”email” = ‘user@example.com’ LIMIT 1

将一周字符串解析为时间(YYYY-W#)

我正在尝试解析一个星期字符串,其中一个类型为“周”的HTML5输入可能返回到ruby中的实际日期或时间。 输入将返回如下字符串:“2014-W05”,其中W05是一年中的第五周。 这是我尝试过的: 2.1.0dev :057 > Time.strptime(“2014-W05”, “%YW%V”) 2014-01-01 00:00:00 -0800 2.1.0dev :058 > Date.strptime(“2014-W05”, “%YW%V”) 2014-01-01 2.1.0dev :058 > DateTime.strptime(“2014-W05”, “%YW%V”) Wed, 01 Jan 2014 00:00:00 +0000 根据文档: http : //apidock.com/ruby/DateTime/strftime %V – 以周为基础的年份的周数(01..53) 谢谢你的帮助!

如何找到@object然后复制@object?

下面的代码预先填充了一个新的_form ,但是一旦用户保存表单,它将更新旧的Inspiration而不是创建新的Inspiration 。 调节器 def new if params[:inspiration_id] @inspiration = Inspiration.find(params[:inspiration_id]) @inspiration = current_user.inspirations.build # Is there a way to find and then build? else @inspiration = current_user.inspirations.build end end 路径 new_inspiration_path(inspiration_id: inspiration.id) 我们怎样才能将@inspiration首先用于Inspiration.find(params[:inspiration_id])然后再使用current_user.inspirations.build ?

Factory Girl + Rspec给出以下错误:ActionView :: Template :: Error :(对象id)不是id值

我定义了一个课程>>级别>>和工厂女孩的步骤。 Step属于level和level属于course(其中每个都有另一种has_many关系)。 这是错误(我甚至不知道从哪里开始): Failure/Error: before { visit course_level_step_path(course.id, level.id, step.id)} ActionView::Template::Error: 0x003fe5daf528a0 is not id value 这是我要求的路线: course_level_step GET /courses/:course_id/levels/:level_id/steps/:id(.:format) steps#show 在这里我的rspec: describe “attempting a step” do let(:course) { FactoryGirl.create(:course)} let(:level) { FactoryGirl.create(:level)} let(:step) { FactoryGirl.create(:step)} before { sign_in user} describe “taking a course” do before { visit course_level_step_path(course.id, level.id, step.id)} <<< here is the […]

生产模式的Ckeditor gem问题

我正在使用CKEditor gem 。 我对application.js和routes.rb配置如下: # application.js //= require ckeditor/init # routes.rb mount Ckeditor::Engine => ‘/ckeditor’ gem在开发模式下工作正常,但是当转到生产模式时,当浏览器请求ckeditor文件夹中的js和css文件时,我得到错误404: GET http://mydomain/assets/ckeditor/config.js?t=D2LI 404 (Not Found) GET http://mydomain/assets/ckeditor/skins/moono/editor.css?t=D2LI 404 (Not Found) GET http://mydomain/assets/ckeditor/lang/vi.js?t=D2LI 404 (Not Found) GET http://mydomain/assets/ckeditor/styles.js?t=D2LI 404 (Not Found) 请帮我修复我的ckeditor路由配置。 先感谢您。

如何在rails迁移中将数据从一个表移动到另一个表?

我已经使用这些资源设置了一个rails网站: 用户(设计)作者 我已经意识到我需要将所有作者移到用户表中,因为我现在正在为这些用户设置角色作为作者。 目前我已经尝试了以下迁移,但没有任何工作,也没有数据传输到users表: class MoveAuthorsColumnDataToUsersTable author.name.downcase.gsub(‘ ‘,”), :encrypted_password => “”, :email => “”, :avatar_file_name => author.avatar_updated_at, :avatar_content_type => author.avatar_content_type, :avatar_file_size => author.avatar_file_size, :avatar_updated_at => author.avatar_updated_at, :role_id => “3” ) end end end 我在控制器中有一个带有属性的作者模型设置,我最终会将所有作者模型关系转移给用户。 author.rb模型: class Author { :large => “980×760”, :medium => “300×300>”, :thumb => “100×100>” }, :default_url => “/images/:style/missing.png” validates_attachment_content_type :avatar, :content_type => […]

按键排序哈希数组,在Ruby中返回降序

我的输入哈希: h = [ {user_id: 1, bookings_nd: 3}, {user_id: 2, bookings_nd: 10}, {user_id: 3, bookings_nd: 2} ] 我需要: h = [ {user_id: 2, bookings_nd: 10}, {user_id: 1, bookings_nd: 3}, {user_id: 3, bookings_nd: 2} ] 怎么做?

如何基于Rails中的哈希键合并哈希数组

我想基于唯一性合并这两个数组: “template_variables”: [{ “info_top”: “Some string” }, { “info_bottom”: “Other string” }], “user_variables”: [{ “info_top”: “Default string” }, { “info_bottom”: “Other default string” }, { “other_info”: “Default number” }] 因此,如果我从user_variables数组开始并向其添加template_variables ,则替换找到匹配项的哈希值。 我想要的输出是: “new_variables”: [{ “info_top”: “Some string” }, { “info_bottom”: “Other string” }, { “other_info”: “Default number” }] 我已经尝试了user_variables.merge(template_variables)及其变体,但这似乎不适合哈希数组。 我该怎么做呢?

Cocoon Gem:未定义的方法`new_record?’ for nil:link_to_remove_association上的NilClass

我正在尝试使用Cocoon Gem构建嵌套表单。 但是我得到的错误如下所示。 我发现Rails Cocoon Gem:Undefined Method’new_record? 在与Wicked的link_to_remove_association上 。 但是,从我的模型代码中可以看出,唯一的答案已被排除。 错误 ActionView::Template::Error (undefined method `new_record?’ for nil:NilClass): 1: 2: 3: 4: app/views/templates/_room_fields.html.erb:3:in `_app_views_templates__room_fields_html_erb__1867913568926009508_70125979350780′ app/views/templates/_form.html.erb:5:in `block (2 levels) in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:4:in `block in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:1:in `_app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/new.html.erb:1:in `_app_views_templates_new_html_erb___3689493092838604682_70125964273280’Models 楷模 class Template true end class Room true end class Item < ActiveRecord::Base belongs_to :room end 表单视图 room […]

错误解析Gemfile; 无法部署到Heroku

很难推到heroku。 我使用最新版本的rails和ruby。 每次我尝试上传到heroku时都会收到此消息。 [code] $ git push heroku master警告:永久性地将IP地址’50 .19.85.132’的RSA主机密钥添加到已知主机列表中。 初始化存储库,完成。 计数对象:69,完成。 Delta压缩使用多达8个线程。 压缩对象:100%(58/58),完成。 书写对象:100%(69/69),15.99 KiB | 0字节/秒,完成。 总计69(delta 5),重复使用0(delta 0) —–> Ruby app detected —–> Compiling Ruby/Rails /app/tmp/buildpacks/ruby/lib/language_pack/helpers/bundler_wrapper.rb:88:in `block in ruby_version’: There was an error parsing your Gemfile, we cannot continue (LanguagePack::Helpers::BundlerWrapper::GemfileParseError) There was an error in your Gemfile, and Bundler cannot continue. from […]