我现在有一个问题,我的数据库中的facebook图形API突然显示所有url图像返回默认图像看起来像这样:
示例网址:
http://graph.facebook.com/{user-id}/picture?type=large
我有一个文件,它是在4个领域name,online,like和score.我想通过多个字段和条件来订购带有分页的百万份文件.
示例一些文档:
我的用户文件:
{ "_id": 1, "name": "A", "online": 1, "like": 10, "score": 1 },
{ "_id": 2, "name": "B", "online": 0, "like": 9, "score": 0 },
{ "_id": 3, "name": "C", "online": 0, "like": 8, "score": 1 },
{ "_id": 4, "name": "D", "online": 1, "like": 8, "score": 0 },
{ "_id": 5, "name": "E", "online": 1, "like": 7, "score": 1 },
{ "_id": 6, "name": "F", "online": 0, "like": 10, …Run Code Online (Sandbox Code Playgroud) 我已经从这个答案实现了多个模型的设计注册.这个user_type从路径中获得了参数.我想用select更改它user_type.因此,当我选择一个值时,将获得一个param user_type select_tag.
我有一些代码看起来像:
的routes.rb
namespace :cp do
devise_scope :user do
match '/add_user' => 'registrations#new'
match '/select/admin' => 'registrations#selectuser', :user => { :usertype => 'admin' }
match '/select/player' => 'registrations#selectuser', :user => { :usertype => 'player' }
end
end
Run Code Online (Sandbox Code Playgroud)
registrations_controller.rb
def selectuser
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
new.html.erb
<h2>Add User</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :username, "Username" %><br />
<%= f.text_field …Run Code Online (Sandbox Code Playgroud) 我已经制作了一个文件管理器,用于在tinyMCE上上传图像,并从另一个文件(attachment_path)获取表单上传和图像列表。首先,我成功获取了图像网址,并field_name在选择图像时将其放置在该位置。但是现在我想在选择图像时将禁用按钮(Insert)更改为false,然后将图像的URL放入按钮(使用自定义属性)。
脚本index_path:
file_browser_callback: function(field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
title: 'My File Manager',
file: "<%= attachments_path %>",
width: 450,
height: 305,
resizable : "no",
inline : "yes",
close_previous : "no",
buttons: [{
text: 'Insert',
classes: 'widget btn primary first abs-layout-item',
disabled: true,
onclick: 'close',
id: 'insertButton'
}, {
text: 'Close',
onclick: 'close',
window : win,
input : field_name
}]
}, {
oninsert: function(url) {
win.document.getElementById(field_name).value = url;
},
onselect: function() {
//
}
}); …Run Code Online (Sandbox Code Playgroud) 我有这样的tb1表:
name email link
john myemail@gmail.com google
john myemail@gmail.com facebook
john myemail2@gmail.com twitter
....
....
and more
Run Code Online (Sandbox Code Playgroud)
当我用查询调用数据时
SELECT name, email, group_concat(DISTINCT link SEPARATOR '/') as source
FROM tb1
group by email
Run Code Online (Sandbox Code Playgroud)
结果像这样:
NAME EMAIL SOURCE
john myemail2@gmail.com twitter
john myemail@gmail.com facebook/google
....
....
and more
Run Code Online (Sandbox Code Playgroud)
我想让结果看起来像:
NAME EMAIL SOURCE 1 SOURCE 2
john myemail2@gmail.com twitter
john myemail@gmail.com facebook google
Run Code Online (Sandbox Code Playgroud)
只有查询才能生成结果吗?
注意:我想制作动态列源1,2,3 ......,n
我有3个模型及其关联
class User < ActiveRecord::Base
# devise modules here
attr_accessible :email, :password, :password_confirmation, :remember_me, :rolable_id, :rolable_type
belongs_to :rolable, :polymorphic => true
end
class Player < ActiveRecord::Base
attr_accessible :age, :name, :position
has_one :user, :as => :rolable
end
class Manager < ActiveRecord::Base
attr_accessible :age, :name
has_one :user, :as => :rolable
end
Run Code Online (Sandbox Code Playgroud)
我从开箱即用的方式放到accepts_nested_attributes_for :rolable用户模型上,在这个带有多态问题属具属问题的accepts_nested_attributes_for中,我找到了一些解决方案,但是所有解决方案都不适合我。所有解决方案,在尝试创建用户时始终出现相同的错误
Processing by RegistrationsController#create as HTML
Parameters: {"utf8"=>"V", "authenticity_token"=>"WKCniJza+PS5umMWCqvxFCZaRVQMPZBT4nU2fl994cU=", "user"=>{"email"=>"john@email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "rolable_type"=>"manager", "rolable"=>{"name"=>"john", "age"=>"24"}}, "commit"=>"Sign up"}
Completed 500 Internal Server Error in 143.0ms …Run Code Online (Sandbox Code Playgroud) 我用Ruby进行了加密和解密,并尝试用Go重写。我一步一步尝试,所以从 ruby 中的加密开始,并尝试在 go 中解密,它是有效的。但是当我尝试在 Go 中编写加密并在 ruby 中解密时。当尝试提取标签时我陷入困境,我解释了为什么我需要提取身份验证标签
ruby 中的加密
plaintext = "Foo bar"
cipher = OpenSSL::Cipher.new('aes-256-gcm')
cipher.encrypt
cipher.iv = iv # string 12 len
cipher.key = key # string 32 len
cipher.auth_data = # string 12 len
cipherText = cipher.update(JSON.generate({value: plaintext})) + cipher.final
authTag = cipher.auth_tag
hexString = (iv + cipherText + authTag).unpack('H*').first
Run Code Online (Sandbox Code Playgroud)
我尝试连接初始向量、密文和身份验证标签,因此在解密之前我可以提取它们,特别是身份验证标签,因为我需要在 Ruby 中调用 Cipher#final 之前设置它
该标签必须在调用 Cipher#decrypt、Cipher#key= 和 Cipher#iv= 之后、调用 Cipher#final 之前设置。执行所有解密后,在调用 Cipher#final 时自动验证标签
这是golang中的函数加密
ciphertext := aesgcm.Seal(nil, []byte(iv), []byte(plaintext), []byte(authData))
src …Run Code Online (Sandbox Code Playgroud) 我有控制器看起来像
class BarsController < ApplicationController
after_action :some_method, only: [:index]
def index
get_cache = $redis.get('some_key')
if get_cache.present?
# i want to skip after_action callback in here
else
# other stuff
end
end
end
Run Code Online (Sandbox Code Playgroud)
after_action :some_method如果get_cache存在,我该如何跳过?我知道我可以像这样有条件地做到这一点
class BarsController < ApplicationController
after_action :some_method, only: [:index], unless: :check_redis
def index
get_cache = $redis.get('some_key')
if get_cache.present?
# i want to skip after_action callback in here
else
# other stuff
end
end
private
def check_redis
$redis.get('some_key')
end
end
Run Code Online (Sandbox Code Playgroud)
但我认为这是多余的,因为应该多次获得redis.
我在模块上有类方法,并放置一个 CONSTANT 并在每个类级方法上调用它
module Cryption
module Crypt
class << self
OFF_ENCRYPT = ENV['IS_OFF']
def encrypt
OFF_ENCRYPT
end
def decrypt
OFF_ENCRYPT
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
该模块创建为 gem
这迫使我在需要类之前设置环境变量
ENV["IS_OFF"] = "YES"
require "bundler/setup"
require "cryption"
Cryption::Crypt.encrypt
# result => "YES"
Run Code Online (Sandbox Code Playgroud)
是否有正确的方法在 rspec 上设置环境变量,我认为在需要模块后无法设置变量
spec_helper.rb
require "bundler/setup"
require "cryption"
Run Code Online (Sandbox Code Playgroud)
crypt_off_spec.rb
RSpec.describe "YES" do
before(:context) do
ENV['IS_OFF'] = "YES"
end
it "encryption off" do
expect(Cryption::Crypt.encrypt).to eq("YES")
end
end
Run Code Online (Sandbox Code Playgroud)
crypt_on_spec.rb
RSpec.describe "NO" do
before(:context) do
ENV['IS_OFF'] = "NO"
end
it "encryption off" do
expect(Cryption::Crypt.encrypt).to …Run Code Online (Sandbox Code Playgroud) 我已经找到了我的问题,但我找不到任何解决方案.
我的模型home:与属性,如title,logo,description,keywords.
我正在使用carrierwave +延迟作业上传a logo,上传工作(创建和更新)但是当文件/输入文件为空时我收到此错误:
ActionController::ParameterMissing in SettingsController#home_update_b
param is missing or the value is empty: home
Extracted source (around line #99):
def home_update_b_params
params.require(:home).permit(:logo)
end
end
Run Code Online (Sandbox Code Playgroud)
SettingsController
def index
## get one record without params
@home = Home.take
end
def home_update_b
@home = Home.find(params[:id])
if @home.update(home_update_b_params)
respond_to do |format|
format.html { redirect_to setting_home_path, :notice => "Logo successfully updated" }
format.json { head :no_content }
end
else
respond_to do …Run Code Online (Sandbox Code Playgroud) devise ×2
ruby ×2
aes-gcm ×1
ajax ×1
carrierwave ×1
delayed-job ×1
facebook ×1
file-manager ×1
go ×1
javascript ×1
jquery ×1
mongodb ×1
mongoid ×1
mysql ×1
rspec ×1
sql ×1
tinymce-4 ×1