1 2 3 4 5 |
csv_string = params[:file].tempfile.open.read.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') CSV.parse(csv_string, headers: true, quote_char: "\x00", force_quotes: true, col_sep: col_sep) do |row| ... end |
1 2 3 4 5 |
csv_string = params[:file].tempfile.open.read.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') CSV.parse(csv_string, headers: true, quote_char: "\x00", force_quotes: true, col_sep: col_sep) do |row| ... end |
1 |
sudo mysql -u root |
1 2 3 4 |
DROP USER 'root'@'localhost'; CREATE USER 'root'@'%' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; |
You don't have to run your Rails app as root to access it on port 80. Instead, run it normally (on port 3000) and forward port 80 packets via iptables…
1 2 3 4 5 |
# localhost/loopback sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000 # external sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000 |
Інсталяція Chrome Extension із iframe заборонена, при спробі отримаємо помилку
Uncaught Chrome Web Store installations can only be started by the top frame.
Варіант вирішення проблеми:
На основній сторінці добавляємо наступний js
1 2 3 4 5 6 7 8 |
<script> window.installChromeExtension = function () { chrome.webstore.install( 'https://chrome.google.com/webstore/detail/...', ); } </script> |
Далу у самому фреймі виконуємо перевірку, якщо це фрейм то викликаємо функцію батьківського вікна, інакше зразу виконуємо інсталяцію
1 2 3 4 5 6 |
if (window.self !== window.top) { window.top.installChromeExtension(); } else { chrome.webstore.install('https://chrome.google.com/webstore/detail/...'); } |
Example:
Gemfile
1 |
gem 'rack-proxy' |
view
1 2 3 4 5 6 7 |
<iframe {...this.props} frameBorder="0" width="1000" height="500" src="/some-url" /> |
config/application.rb
1 2 3 4 5 |
require_relative '../lib/proxy/service_proxy' ... class Application < Rails::Application ... config.middleware.use ServiceProxy |
lib/proxy/service_proxy.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
require 'rack/proxy' class ServiceProxy < Rack::Proxy def initialize(app) @app = app @allow_urls = %w[/some-url /some-url2] end def rewrite_env(env) if @allow_urls.include?(env['PATH_INFO']) env["HTTP_HOST"] = "any_domain.com" env["SERVER_PORT"] = 443 env['HTTPS'] = 'on' end env end def call(env) if @allow_urls.include?(env['PATH_INFO']) rewrite_env(env) rewrite_response(perform_request(rewrite_env(env))) else @app.call(env) end end end |
1 2 3 4 5 6 7 |
$('#submit-btn').on('click', function () { if ($('#new_user')[0].checkValidity()) { $('#new_user').submit(); $('.status-error').remove(); $('.add-error').removeClass('has-error'); } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$('form#new_user').bind('ajax:success', () => { animationSignUpForm(); setTimeout(() => window.location.replace('/'), 2000); }); $('form#new_user').bind('ajax:error', (evt, xhr) => { $('form#new_user').prepend( '<div class="alert alert-danger status-error">Please review the problems below:</div>', ); $('.form-group.email.user_email'); var errors = xhr.responseJSON.errors; for (key in errors) { var array = errors[key]; var element = `.form-group.${key}.user_${key}`; $(element).addClass('add-error has-error'); array.forEach(function(item){ $(element).append(`<span class="help-block status-error">${item}</span>`); }); } }); |
1 2 |
class Users::RegistrationsController < Devise::RegistrationsController respond_to :html, :json |
1 2 3 |
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), remote: true, data: { type: :json }) do |f| %> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
let(:chrome_driver_path) { `whereis chromedriver`.strip.split(' ')[1] } ... it 'checks something' do browser = Selenium::WebDriver.for(:chrome, driver_path: chrome_driver_path) begin browser.get('file:///tmp/document.html') browser.find_elements(css: '.data').each do |element| expect(element.style('width').to_i).to be >= 300 end ensure browser.quit end end |
gem 'omniauth-google-oauth2' – sign in and sign up with google
Sphinx (англ. SQL Phrase Index) — система повнотекстового пошуку. Відмінною особливістю є висока швидкість індексації та пошуку, а також інтеграція з існуючими СУБД (MySQL, PostgreSQL) та наявність API для поширених мов веб-програмування
В рубі використовуємо gem thinking-sphinx
Офіційна документація A Ruby connector between Sphinx and ActiveRecord.
Thinking Sphinx on Ruby on Rails: Part 1
Thinking Sphinx on Ruby on Rails: Part 2
postgres_ext – цей gem не повинен використовуватися якщо у вас Rails 5 (пів дня вбив поки знайшов проблему, що запит на пошук працює але результат нульовий)