ruby on rails教程ch 10可以获得邮件但链接错误也Bitbucket无法添加代码

我已经部分解决了这个问题:我可以获得确认和重置密码的链接。 问题是这些链接指向错误的应用程序,我需要手动调整应用程序的名称,以获得正确的重定向。 Heroku代表说那些错误的地址与代码有关…. 1.在Michael Harti ruby​​ on rails教程中我可以找到并更改代码吗? 我使用Cloud 9和Bitbucket作为存储库。 我已经在Bitbucket上创建了新应用程序克隆我现有的应用程序,从Bitbucket到Cloud,并希望将其推送到Bitbucket以进行一些更改。 但Bitbucket不允许我说有现有的应用程序。 克隆可能在这种情况下不起作用。 2.如何创建与Bitbucket中现有完全相同的应用程序,但在Cloud9上使用不同的名称并将其推送到具有不同名称的Bitbucket? 谢谢。 //config/environments/production.rb config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method =:smtp host =’tatyanaa.herokuapp.com’ config.action_mailer.default_url_options = {host:host} ActionMailer :: Base.smtp_settings = { :address => ‘smtp.sendgrid.net’, :port => ‘587’, :authentication => :plain, :user_name => ENV[‘SENDGRID_USERNAME’], :password => ENV[‘SENDGRID_PASSWORD’], :domain => ‘heroku.com’, :enable_starttls_auto => true }

在Ubuntu上运行Rails时遇到问题

首先是一些背景。 我正在尝试在全新安装的Ubuntu上运行Community Engine 。 CE是一个在Rails上运行的开放式src社交网络插件。 我能够在没有问题的情况下在我的Windows机器上运行CE并运行。 我现在决定使用Ubuntu 8.10作为我的开发环境,并坚持这个问题。 我在过去的几个晚上研究了这个,但仍然卡住了。 当我到达指令的这一步( 在此处找到 )时会发生什么: Generate the community engine migrations: $ script/generate plugin_migration 我收到以下错误: myuser@compy:~/Projects/MyProject$ script/generate plugin_migration /home/myuser/Projects/MyProject/config/../vendor/plugins/engines/boot.rb:4: This version of the engines plugin requires Rails 2.1.1 or later! (RuntimeError) from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’ from /home/myuser/Projects/MyProject/config/environment.rb:12 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’ from /home/myuser/Projects/MyProject/vendor/rails/railties/lib/commands/generate.rb:1 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in […]

如何从rails控制台将图像从url保存到本地ubuntu文件夹?

我需要从一些网站编写图像解析器,它将获取图像,其他一些信息并保存到我的本地文件夹。 所以,假设我们在此url上有图片: https : //i.stack.imgur.com/MiqEv.jpg (这是某人的SO头像) 所以我想将它保存到本地文件夹。 让我们说”~/test/image.png”我找到了这个链接 我在我的终端尝试了这个: rails console require ‘open-uri’ open(‘~/test/image.jpg’, ‘wb’) do |file| file << open('https://i.stack.imgur.com/MiqEv.jpg').read end 如您所见,我的home / test文件夹为空 我从控制台#获得此输出 我该怎么办? 我也试过这个: require ‘open-uri’ download = open(‘https://i.stack.imgur.com/MiqEv.jpg’) IO.copy_stream(download, ‘~/test/image.jpg’) 得到了这个输出: => #https://i.stack.imgur.com/MiqEv.jpg>,@ meta = {“date”=>“星期五,2016年5月6日11:58:05 GMT”,“content-type”=> “image / jpeg”,“content-length”=>“4276”,“connection”=>“keep-alive”,“set-cookie”=>“__ cfduid = d7f982c0742bf40e58d626659c65a88841462535885; expires = Sat,06-May-17 11 :58:05 GMT; path = […]

Rails 4 – 轮播助手 – 图片库

我试图了解如何调整本教程,以制作我可以在我的Rails 4应用程序中使用的轮播助手。 https://www.toptal.com/ruby-on-rails/rails-helper-bootstrap-carousel 我帮助了: module CarouselHelper def carousel_for(images) Carousel.new(self, images).html end class Carousel def initialize(view, images) @view, @images = view, images @uid = SecureRandom.hex(6) end def html content = safe_join([indicators, slides, controls]) content_tag(:div, content, id: uid, class: ‘carousel slide’) end private attr_accessor :view, :images, :uid delegate :link_to, :content_tag, :image_tag, :safe_join, to: :view def indicators items […]

为什么控制器方法中定义的实例变量不在相应的部分中可用?

例如,给定一个基本控制器,例如: class PostsController < ApplicationController def index @post = Post.all end 实例变量@post在视图posts/index.html.erb可用,但不在部分posts/_index.html.erb 我的主要问题是:这是为什么? 如何在控制器中为部分定义方法,例如,传递实例变量? 更具体的说明:我问这个是因为我在单独的主视图welcome/index.html.erb呈现数据的方式是通过这个post部分。 我已经通过posts/_index.html.erb partial中的Post.all直接调用模型来解决这个限制,但据我所知,这忽略了MVC架构并严重限制我开发更复杂的方法,除非我真的打破约定并将它们写入视图(我认为它可能有用,但设计很差)。 目前,@ post将nil传递给部分符号:welcome / index.html.erb中的post 很明显我错过了什么,所以任何见解都会非常感激! 谢谢 相关文件: views/ posts/ _index.html.erb _new.html.erb show.html.erb welcome/ index.html.erb controllers/ posts_controller.rb welcome_controller.rb 文章/ _index.html.erb 文章/ _new.html.erb 文章/ show.html.erb welcome / index.html.erb相关部分(部分) 控制器/ posts_controller.rb class PostsController < ApplicationController def new end def create @post […]

在rails中创建新对象时出错

每当我尝试为模型创建对象时,我都会在rails中收到此错误。 我正在使用Windows 7 C:\Ruby\joker\chapter3>ruby script/console Loading development environment (Rails 2.3.8) >> mycb = ComicBook.new SyntaxError: C:/Ruby/joker/chapter3/app/models/comic_book.rb:19: syntax error, u nexpected $end, expecting kEND from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_without_new_constant_marking’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:521:in `new_constants_in’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:379:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:259:in `require_or_load’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:425:in `load_missing_constant’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:80:in `const_missing’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:92:in `const_missing’ […]

是否可以调用ActiveResource :: Base#load?

ActiveResource::Base#update_attributes方法调用ActiveResource::Base#load方法,该方法在activeresource-3.1.3/lib/active_resource/base.rb (第1255行)中定义。 我试图调用该load方法,而不是简单地使用update_attributes以便不立即保存该对象。 我用一个全新的rails应用程序测试了它。 我搭建了一个简单的对象: rails scaffold obj property1:string 然后在rails控制台中: irb(main):001:0> obj=Obj.new irb(main):002:0> obj.load(:property1=>”data”) TypeError: can’t convert Hash into String from …/activesupport-3.1.3/lib/active_support/dependencies.rb:234:in `load’ from …/activesupport-3.1.3/lib/active_support/dependencies.rb:234:in `load’ from …/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency’ from …/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in’ from …/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency’ from …/activesupport-3.1.3/lib/active_support/dependencies.rb:234:in `load’ from (irb):2 我看到activesupport-3.1.3/lib/active_support/dependencies.rb将其Loadable模块应用于Object ,为每个对象提供加载文件的load方法,但我无法弄清楚为什么它会覆盖ActiveResource::Base#load方法,而不是相反。 我正在使用Rails 3.1.3和朋友。 更新: 我想我已经回答了我自己的问题。 我一直在尝试在ActiveRecord对象上使用ActiveResource方法。 我知道我的Rails模型类是ActiveRecord::Base后代,但是当我试图找到ActiveRecord::Base#update_attributes的代码时,我找到了ActiveResource::Base#update_attributes的代码,它看起来像这样: def update_attributes(attributes) load(attributes, false) && save end […]

创建与.build的关联并解决参数validation问题

使用Rails 3.2.9 我正在尝试使用.build而不是.create构建一个关联,但是获得了一个密码validation错误,我似乎无法找到解决方法。 点评如下: 我理解的方法是保存一个使用.build构建的关联的项目,你实际上必须在这个案例中对所有者进行保存。 如果你在@item上进行保存,它只是创建项而不是关联(意味着它不会保存到DB,直到current_owner.save)。 当我对所有者进行保存时,由于密码不符合validation要求,我遇到了错误。 有没有办法在我进行保存时绕过validation,因为我需要为密码实现不同的解决方案,或者只是停止抱怨并使用.create而不是.build。 下面给出的密码不符合validation错误 @item = current_owner.items.build(params[:item]) if current_owner.save Do some other work with item end 我想我可以做以下事情(出于某种原因,它似乎对我来说可能不是。想法?) @item = current_owner.items.create(params[:item]) if !@item.nil? Do some other work with item end 表设置:所有者: ID 名称 encrypted_pa​​ssword 盐 项目: ID 名称 items_owners: owner_id ITEM_ID 楷模: class Item :items_owner end class Owner :items_owner before_save :encrypt_password […]

使用Rails 5枚举PGarrays

我正在尝试将Rails的枚举用于PostgreSQL的数组列。 class Post < ActiveRecord::Base enum tags: { a: 0, b: 1, c: 2 }, array: true end 但是上面的代码不起作用 有没有办法在数组列上使用枚举像arrtibute支持array: true ? 编辑 我想看到以下测试用例通过,但实际上它失败了。 # frozen_string_literal: true begin require “bundler/inline” rescue LoadError => e $stderr.puts “Bundler version 1.10 or later is required. Please update your Bundler” raise e end gemfile(true) do source “https://rubygems.org” git_source(:github) { […]

我不明白为什么这个platformatic邮件表单联系表单不起作用

车型/ lead.rb class Lead “My Contact Form”, :to => “callumshorty@hotmail.com”, :from => “admin@uk-franchise.co.uk” } end end 控制器/ lead_form_controller.rb class LeadFormController < ApplicationController def new @lead = Lead.new end def create @lead = Lead.new(params[:lead_form]) @lead.request = request @lead.deliver end end 的routes.rb resources :lead_form 视图/列表/ show.html.erb url_for(:controller => ‘lead_form’, :action => ‘new’) do |lead| %> 尝试访问显示页面时出错: First […]