Tag: ruby on rails 4

Rails遍历来自API XML响应的哈希

我有一个使用Httparty从API收到的哈希。 响应是XML,但httparty将其显示为哈希。 但它太深了,获得价值会让人感到困惑。 {“ air_search_result ”=> {“xmlns”=>“ http://www.cleartrip.com/air/ ”,“ onward_solutions ”=> {“ solution ”=> [{“index”=>“1”,“ pricing_summary “=> {”base_fare“=>”3350.0“,”tax“=>”7828.55“,”total_fare“=>”11178.55“},” flights “=> {” flight “=> {” segments “=> {“ segment ”=> [{“index”=>“1”,“departure_airport”=>“BOM”,“arrival_airport”=>“BLR”,“departure_date_time”=>“2014-07-06T09:15:00 “,”arrival_date_time“=>”2014-07-06T10:50:00“,”flight_number“=>”639“,”航空公司“=>”AI“,”operating_airline“=>”AI“,”停止“= >“0”,“equipment”=>“319”,“duration”=>“5700”},{“index”=>“2”,“departure_airport”=>“BLR”,“arrival_airport”=>“DEL “,”arrival_terminal“=>”3“,”departure_date_time“=>”2014-07-06T20:10:00“,”arrival_date_time“=>”2014-07-06T22:40:00“,”flight_number“=> “404”,“airline”=>“AI”,“operating_airline”=>“AI”,“停止”=>“0”,“设备”=>“320”,“持续时间”=>“9000”}] },“ pax_pricing_info_list ”=> {“ pax_pricing_info ”=> {“pax_type”=>“ADT”,“ pricing_info_list ”=> {“ pricing_info ”=> {“index”=>“1”,“fare_basi s_code“=>”SAP30,SAP30“,…….. 我需要进入并显示航空公司,departure_airport等。 “航class”=> { “飞行”=> { “段”=> { […]

载波图像未加载到源代码中

不知道我在这个问题上做错了什么。 我已经按照Rails Cast for Carrierwave进行了操作,但是我遇到了一个奇怪的错误,图像根本没有显示 – (HTML)源代码显示的是图像标记,但内部没有任何内容。 组合模型代码: class Portfolio < ActiveRecord::Base validates :title, :content, presence: true mount_uploader :feature_image, FeatureImageUploader end function图像上传代码: class FeatureImageUploader < CarrierWave::Uploader::Base storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def extension_white_list %w(jpg jpeg gif png) end end Show.html.haml代码: = @portfolio.title =image_tag @portfolio.feature_image_url.to_s =markdown(@portfolio.content).html_safe 我的表格代码: .field = f.label :title %br = f.text_field :title […]

无法在Ruby on Rails 4.1.4中安装activerecord

我无法在Ruby on Rails 4.1.4中安装activerecord 。 我已经在gem ‘activeadmin’, github: ‘activeadmin’添加了gem ‘activeadmin’, github: ‘activeadmin’并运行bundle install 。 它返回0,所以我试图运行rails g active_admin:install命令,但它返回以下错误: NameError:未定义的局部变量或方法install’for install’ for main:Object from (irb):3 from E:/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/console.rb:90:in start’来自E:/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/console.rb: 9: start’ from E:/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:69:in console’来自E :/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in run_command!’ from E:/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in run_command!’ from E:/software/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in E:/ work / projects / src / technical_support_timer / bin / rails:4:in require’ from E:/work/projects/src/technical_support_timer/bin/rails:4:in in’from -e:1:in […]

如何解决ROR-4中的NoMethod错误

请帮我解决以下错误。 当我输入rake db:在ruby cmd中创建时,我遇到了这种类型的错误。 错误: rake aborted! NoMethodError: undefined method `each’ for # Tasks: TOP => db:create => db:load_config (See full trace by running task with –trace) 我的database.yml和gem文件如下。 配置/ database.yml的 # MySQL. Versions 5.0+ are recommended. # # Install the MYSQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in […]

在Rails中,我可以通过委托方法订购查询吗?

我很难通过委托方法订购查询。 我的任务是帮助将一个相当大的Rails 3应用程序升级到Rails 4.我在索引操作中遇到了这个查询。 我知道这些对象的命名是可怕和令人困惑的。 # measurements_controller.rb def index @measurements = Measurement.includes(:identifier).order(:name) end 在Rails 4中,我收到此错误: ERROR: column info_items.name does not exist LINE 1: …D (info_item_identifiers.name LIKE ‘%’) ORDER BY “info_item… 所以我看了一下模型,发现: # measurement.rb class Measurement < InfoItem … end # info_item.rb belongs_to :identifier, class_name: 'InfoItemIdentifier' delegate :name, :name=, to: :identifier # info_item_identifier.rb # This object […]

如何使用嵌套属性在多对一自引用模型中创建/更新Rails中的对象?

我的Rails 4应用程序有一个主题模型,允许多对多的自引用关系。 我基于这个奇妙的答案设置了模型,为多对多自连接创建模型,如果我手动填充关系表,它似乎有效。 让我们使用该模型来解决问题: user.rb: class User < ActiveRecord::Base # follower_follows "names" the Follow join table for accessing through the follower association has_many :follower_follows, foreign_key: :followee_id, class_name: "Follow" # source: :follower matches with the belong_to :follower identification in the Follow model has_many :followers, through: :follower_follows, source: :follower # followee_follows "names" the Follow join table for […]

每次`params`包含`redirect_uri`值时,如何将用户重定向到自定义网页?

我正在运行Ruby on Rails 4.1,我希望实现一个function,当用户通过提供redirect_uri参数执行操作时,将用户重定向到自定义网页。 换句话说,我希望每次在params出现redirect_uri值时“触发”重定向,并且重定向应该在任何情况下发生(例如,当使用HTML或JS格式执行GET,POST,PUT和DELETE HTTP请求时) )在完成流程流程之后(例如,当HTTP动词为POST时,重定向应在提交后发生)。 奖励 – 如果可能,我想在引荐来源url来自应用程序域之外的情况下validationURL(例如,链接正确性)。 我应该如何正确地做到这一点?

Ruby on Rails – 如何从嵌套模型委派错误消息

class User include Mongoid::Document has_many :images accepts_nested_attributes_for :image end class Image include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paperclip has_mongoid_attached_file :uploaded_image, :path => “:rails_root/public/uploads/:class/:id/:basename.:extension”, :url => “public/uploads/” validates_attachment_content_type :uploaded_file, :content_type => “application/png”, :message => “error massage” belongs_to :user delegate :url, :path, to: :uploaded_image, allow_nil: true, prefix: false end 如果:uploaded_image无效,如何将Image中的错误委托给用户? 例如: user_image = user.images.build(uploaded_image: new_image.path) user_image.save 如果uploaded_image无效,应该引发错误。

停止从谷歌的API获取刷新令牌

所以我有一个带有ruby on rails的web应用程序连接到google drive的API。 到目前为止,它曾用于接收刷新令牌,因为我使用的其中一个参数是离线的。 但最近它停止了它。 正在发送的url是: Redirected to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=ID&options=%7B:access_type=%3E%22offline%22,%20:approval_prompt=%3E%22force%22%7D&redirect_uri=http://localhost:3000/oauth2callbackdrive&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/userinfo.email 重定向到URI的代码包含: client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI auth_url = client.authorization.authorization_uri(:options => {:access_type => :offline, :approval_prompt => :force}.to_s) redirect_to auth_url.to_s 在回调函数上我有这个: client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI client.authorization.code […]

Ruby on Rails嵌套属性没有保存到数据库中?

我正在尝试在“Todo列表”中创建项目列表,但是,我不确定我是否正确使用嵌套属性执行此操作。 我认为使用嵌套属性是正确的尝试,因为会有一个大的项目列表,并且它将与基于ids的正确“待办事项列表”相关联。 填充记录时表格的示例 待办事项表 id list 1 grocery shopping 2 health insurance 物品表 id todo_id name 1 1 buy milk 2 1 buy cereal 3 2 Blue Shield 4 2 Healthnet 5 1 buy cherries 虽然我的尝试如下,但我的应用程序没有将任何数据保存到Item数据库中。 Todo控制器 class TodoController < ApplicationController def new @todo = Todo.new @todo.items.build end end Todo模型 class Todo < ActiveRecord::Base belongs_to […]