我尝试使用capistrano部署我的rails网站.所以,当我跑
cap production deploy
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
(Backtrace restricted to imported tasks)
cap aborted!
Don't know how to build task 'start' (see --tasks)
Tasks: TOP => production
Run Code Online (Sandbox Code Playgroud)
这是我的上限文件
# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Run Code Online (Sandbox Code Playgroud)
这是我的deploy.rb
set :repo_url, 'xxx'
set :application, 'xxx'
set :user, 'yyy'
set :puma_threads, [4, 16] …Run Code Online (Sandbox Code Playgroud) 现在我通过使用browserify-rails编译js文件,在Ruby on Rails应用程序(使用react-rails gem)上创建React应用程序.
所以我试着让我们反应路由器来配置应用程序的路由器
这是我的main.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router';
import { browserHistory } from 'react-router';
/*Import Component*/
import DashBoard from './components/dashboard';
import Group from './components/dashboard';
/*
*
* Routes
*
* */
var routes = (
<Router history={browserHistory}>
<Route path="/" component={DashBoard}/>
<Route path="/group" component={Group}/>
</Router>
);
ReactDOM.render(routes , document.querySelector('#main'));
Run Code Online (Sandbox Code Playgroud)
但是当我去的时候
http://my.app.dev/group
Run Code Online (Sandbox Code Playgroud)
我有
No route matches [GET] "/group" (From Rails)
Run Code Online (Sandbox Code Playgroud)
那么我该如何解决这个问题并将Ract路由器置于Rails路由器之上呢?
谢谢!
我使用此链接作为我的起始文件制作了项目.
https://github.com/facebookincubator/create-react-app
但在我试图制作Facebook登录按钮后,跟随他们的官方文档.
componentDidMount(){
console.log('login mount');
window.fbAsyncInit = function() {
FB.init({
appId : '320866754951228',
xfbml : true,
version : 'v2.6'
});
FB.getLoginStatus(function(response) {
//this.statusChangeCallback(response);
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
Run Code Online (Sandbox Code Playgroud)
所以我在刷新浏览器时遇到了这个错误.
Failed to compile.
Error in ./src/components/user_profile/LoginForm.js
/Sites/full_stack_production/xxxxx
70:13 error 'FB' is not defined no-undef
76:13 error 'FB' is not defined no-undef
? 2 problems (2 errors, 0 …Run Code Online (Sandbox Code Playgroud) 我正在使用 typescript、express 和Sequelize.
这是我的database连接类。
export class Database {
private _sequelize: Sequelize;
private config: DBConfigGroup = dbConfig;
private env = process.env.NODE_ENV as string;
constructor() {
this._sequelize = new Sequelize({
dialect: 'postgres',
database: this.config[this.env].database,
username: this.config[this.env].username,
password: this.config[this.env].password,
host: this.config[this.env].host,
});
}
async connect(): Promise<void> {
try {
console.log('start connect');
await this._sequelize.authenticate();
console.log('Connection has been established successfully.'.green.bold);
} catch (error) {
console.error('Unable to connect to the database:'.red.bold, error);
}
}
async close(): Promise<void> {
try {
await this._sequelize.close(); …Run Code Online (Sandbox Code Playgroud) node.js sequelize.js google-cloud-sql google-cloud-platform docker-compose
我正在使用Webpacker工作Rails5项目,以便正确运行React
但是当import我的根组件中的css文件看起来根本不起作用时.看起来样式表根本就没有了.
这是我的根组件
import React from 'react'
import ReactDOM from 'react-dom'
import StartForm from './insurance_form/start_form'
//import PropTypes from 'prop-types'
import 'react-datepicker/dist/react-datepicker.css';
// not working
ReactDOM.render(
<StartForm />,
document.getElementById('start-form-index-container')
)
Run Code Online (Sandbox Code Playgroud)
这是我的 webpack/environment.js
const { environment } = require('@rails/webpacker')
const merge = require('webpack-merge')
const myCssLoaderOptions = {
modules: true,
sourceMap: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
const CSSLoader = environment.loaders.get('style').use.find(el => el.loader === 'css-loader')
CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)
module.exports = environment
Run Code Online (Sandbox Code Playgroud)
那么我如何使用webpacker使导入的css运行良好?
谢谢!
我试图为我现有的项目创建测试文件
https://github.com/facebookincubator/create-react-app
但是我跑的时候遇到了这个错误 npm test a
FAIL src/__tests__/movie_single/MovieSingle-test.js
? Test suite failed to run
matchMedia not present, legacy browsers require a polyfill
at Object.MediaQueryDispatch (node_modules/enquire.js/dist/enquire.js:226:19)
at node_modules/enquire.js/dist/enquire.js:291:9
at Object.<anonymous>.i (node_modules/enquire.js/dist/enquire.js:11:20)
at Object.<anonymous> (node_modules/enquire.js/dist/enquire.js:21:2)
at Object.<anonymous> (node_modules/react-responsive-mixin/index.js:2:28)
at Object.<anonymous> (node_modules/react-slick/lib/slider.js:19:29)
at Object.<anonymous> (node_modules/react-slick/lib/index.js:3:18)
at Object.<anonymous> (src/components/movie_single/MovieDetailsBox.js:4:45)
at Object.<anonymous> (src/components/movie_single/MovieSingle.js:3:50)
at Object.<anonymous> (src/__tests__/movie_single/MovieSingle-test.js:3:46)
at process._tickCallback (internal/process/next_tick.js:103:7)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.642s
Ran all test suites matching "a".
Run Code Online (Sandbox Code Playgroud)
所以这是我的 package.json
{
"name": "xxx",
"version": …Run Code Online (Sandbox Code Playgroud) 我在Puma和Nginx上使用ActionCable通过Rails创建网站.
但是在部署到Production服务器之后,似乎ActionCable因为这个问题而无法正常工作.WebSocket连接到
WebSocket connection to
'ws://sub.domain.com/cable' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
Run Code Online (Sandbox Code Playgroud)
这是我的 production.rb
config.action_cable.url = 'ws://sub.domain.com/cable'
config.web_socket_server_url = "ws://sub.domain.com/cable"
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
config.action_cable.disable_request_forgery_protection = true
Run Code Online (Sandbox Code Playgroud)
这是我的nginx.conf
upstream puma {
server unix:///home/deploy/apps/app_name/shared/tmp/sockets/app_name-puma.sock;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/deploy/apps/app_name/current/public;
access_log /home/deploy/apps/app_name/current/log/nginx.access.log;
error_log /home/deploy/apps/app_name/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
} …Run Code Online (Sandbox Code Playgroud) 我正在研究前端的Reactjs redux和后端的Rails api.
所以现在我用Fetch api方法调用api,但问题是我无法获得可读的错误信息,就像我在网络选项卡中得到的一样
这是我的功能
export function create_user(user,userInfoParams={}) {
return function (dispatch) {
dispatch(update_user(user));
return fetch(deafaultUrl + '/v1/users/',
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(userInfoParams)
})
.then(function(response) {
console.log(response);
console.log(response.body);
console.log(response.message);
console.log(response.errors);
console.log(response.json());
dispatch(update_errors(response));
if (response.status >= 400) {
throw new Error("Bad response from server");
}
})
.then(function(json){
console.log("succeed json re");
// We can dispatch many times!
// Here, we update the app state with the results of the API call.
dispatch(update_user(json));
});
} …Run Code Online (Sandbox Code Playgroud) 我正在开发Reactjs用作前端和Rails5 api only应用程序作为后端的Web应用程序
这是我发送到服务器的数据 Request payload
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[username]"
oeuoeoaeaoe
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[profile_image]"; filename="gggg.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryCD1o71UpVNpU4v86--
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
def update_with_image
user = current_user
if user.update_attributes(user_update_params)
# Handle a successful update.
render json: user, status: 200
else
render json: { errors: user.errors }, status: 422
end
end
private
def user_update_params
params.require(:user).permit(:username,:profile_image)
end
Run Code Online (Sandbox Code Playgroud)
所以当我试图将图像上传到Rails服务器时,我遇到了这个错误
ActionController::BadRequest (Invalid request parameters: invalid %-encoding ("user[username]"
oeuoeoaeaoe
------WebKitFormBoundaryCD1o71UpVNpU4v86
Content-Disposition: form-data; name="user[profile_image]"; filename="gggg.jpg"
Content-Type: image/jpeg
????JFIF????@6"??
??F!1AQ "aq?
#2???B?????$3Rb?%Cr?????? ??A!1A"Qaq?2???BR???#b??3rS?$Cs????
??%)):
rack …Run Code Online (Sandbox Code Playgroud) 我试图通过Capistrano将Rails应用程序部署到服务器.这是我在deploy.rb上的代码
set :repo_url, 'git@bitbucket.org:varisdaOfficial/insurance_site.git'
set :application, 'insurance_code'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
set :linked_dirs, %w(public/uploads)
namespace :puma do …Run Code Online (Sandbox Code Playgroud) reactjs ×4
capistrano ×2
javascript ×2
actioncable ×1
eslint ×1
facebook ×1
fetch-api ×1
jestjs ×1
nginx ×1
node.js ×1
puma ×1
rack ×1
rack-cors ×1
rackattack ×1
sequelize.js ×1
webpack ×1
webpacker ×1