Tag: ruby on rails 4

Omniauth Facebook没有返回电子邮件和性别轨道4

我需要从Facebook获取姓名,电子邮件,图片和性别。 我得到名字和图像,但电子邮件和性别不是从Facebook获取。 我过去2天都在苦苦挣扎,任何人都可以帮助我。 用户模型: def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.email = auth.info.email user.gender = auth.extra.raw_info.gender #if user.gender.blank? user.image = auth.info.image user.save! end end Omniauth.rb OmniAuth.config.logger = Rails.logger Rails.application.config.middleware.use OmniAuth::Builder do if Rails.env.production? provider :facebook, ‘APP_ID’, ‘APP_SEC’ elsif Rails.env.development? provider :facebook, ‘APP_ID’, ‘APP_SEC’, {:scope […]

Heroku是否支持ActionController :: Live?

我有一个在Heroku上托管的Rails应用程序,我想添加Server Sent Eventsfunction,但我找不到任何特定于Heroku的文档或博客文章。 由于并非所有服务器(例如WEBrick)都支持ActionController :: Live,我想知道Heroku上的默认服务器是什么,以及是否可以配置环境(即更改服务器)以支持SSE。 关于服务器使用和如何配置的任何进一步建议将不胜感激。

mongodb mongoid-rails无法在嵌入文档的散列中增加计数器

我使用的是Mongoid 4.0.2,Rails 4.2.1和Mongodb 2.4.8。 我将daily_events作为人员集合中的嵌入文档,如下所示。 class Person include Mongoid::Document field :email, type: String field :month, type: Date field :monthly_total, type: Hash, default: {:email_open => 0, :email_click => 0, :page_view => 0} embeds_many :daily_events end class DailyEvent include Mongoid::Document field :name, type: String field :day_1, type: Hash, default: -> {:email_open => 0, :email_click => 0, :page_view […]

使用.env文件在生产中设置SECRET_KEY_BASE

我在生产中的根文件夹中有一个.env文件。 此文件定义了在config/secrets.yml使用的SECRET_KEY_BASE 。 问题是我无法在config/secrets.yml .env之前加载我的.env文件。 我尝试过使用dotenv gem而没有成功。 关于如何在生产中做到这一点的任何想法? 我不想为生产服务器上的webmaster用户全局设置它。 应该只能由应用程序访问SECRET_KEY_BASE值。 我正在使用rails 4.1。

如何validationRails中的重叠时间

我有一个Event model ,它在我的日程安排应用程序中有时间和时间,我想在保存之前validation重叠时间。 我的观点图如下; Departure date: Dec 31, 2016 Day1 07:00 – 07:20 event1 10:30 – 11:30 event2 15:40 – 16:10 event3 [add event button] Day2 08:15 – 09:05 event4 12:08 – 13:04 event5 14:00 – 14:25 event6 [add event button] [save schedule button] from时间和时间可以同时改变和添加。 我想做的是显示错误,如果我尝试为Day1添加(或更改) 07:05 – 07:30 ,例如, 13:50 – 14:30 ,依此类推。 虽然我尝试了一些overlap代码, […]

按日期循环变量分组

我有一些运动成绩,我想循环,并在表格中的日期分组。 例如; |Sat, 20| |Game 1 Results| |Game 2 Results| |Sun, 21| |Game 3 Results| |Sat, 27| |Game 4 Results| 我的控制器 @matches = Match.group([:matchId, ‘DATE(matchDate)’]).inject([]) do |results, matches| team_names = Match.where(matchId: matches.matchId) results << [matches.id, matches.matchDate, team_names.first.team.name, team_names.last.team.name, team_names.first.points, team_names.last.points] end 目前我正在做一个基本循环,正在显示。 |Sat, 20| |Game 1 Results| |Sat, 20| |Game 2 Results| |Sun, 21| |Game […]

如何显示在线用户

我正在写一个简单的聊天,我需要在线列出用户。 我没有使用devise进行身份validation,有一个自定义user模型通过omniauth进行身份validation。 user.rb class User < ActiveRecord::Base has_many :messages, dependent: :delete_all class << self def from_omniauth(auth) provider = auth.provider uid = auth.uid info = auth.info.symbolize_keys! user = User.find_or_initialize_by(uid: uid, provider: provider) user.name = info.name user.avatar_url = info.image user.profile_url = info.urls.send(provider.capitalize.to_sym) user.save! user end end end application_controller.rb def current_user @current_user ||= User.find_by(id: cookies[:user_id]) if cookies[:user_id] end […]

如何在不同的命名空间Rails 4.2中遵循DRY原则?

基本上我开发了一个有两个命名空间的应用程序: admin , api和public(只是resources :users例如resources :users )。 一切正常,但我正在重复自己,因为api一些控制器可以很容易地用于admin 。 在这种情况下如何保留命名空间? 谢谢!

找到多态关联或无差异的记录

我有一个运行ruby 2.1.2和rails 4.1.1的rails应用程序,在其中我有一个多态关联,如下所示: class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true end class Employee < ActiveRecord::Base has_many :pictures, as: :imageable end class Product < ActiveRecord::Base has_many :pictures, as: :imageable end 我希望能够找到属于给定员工或没有关联的“可成像”记录的所有图片。 # These both work fine Picture.where(imageable: Employee.first) # finds all associated with Employee.first Picture.where(imageable: nil) # finds all un-associated Pictures #This does not work […]

使用名称中的数字为列创建迁移

我正在将一个应用程序移植到rails中,并且有几个列被命名为 2nd_phone 2nd_address 当我尝试使用t.string:2nd_phone进行迁移时 我收到语法错误,意外的tINTEGER,期待tSTRING_CONTENT或tSTRING_DBEG或tSTRING_DVAR或tSTRING_END 任何想法如何在rals?