小编Evo*_*tio的帖子

actioncable 无法连接到 websocket

我无法连接到可操作的网络套接字。

我将此行添加到我的routes.rb中

match "/websocket", :to => ActionCable.server, via: [:get, :post]
Run Code Online (Sandbox Code Playgroud)

我将此文件添加到我的应用程序路径:cable/config.ru

# cable/config.ru
require ::File.expand_path('../../config/environment',  __FILE__)
Rails.application.eager_load!

require 'action_cable/process/logging'

run ActionCable.server
Run Code Online (Sandbox Code Playgroud)

频道/application_cable/channel.rb

module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end
Run Code Online (Sandbox Code Playgroud)

通道/application_cable/connection.rb

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    protected
      def find_verified_user
        if current_user
          current_user
        else
          reject_unauthorized_connection
        end
      end
  end
end
Run Code Online (Sandbox Code Playgroud)

和我的 javascriptfiles 下的 asset/javascript/channels/index.coffee

#= require cable
#= require_self
#= require_tree .

@App = {}
# App.cable = Cable.createConsumer 'ws://localhost:28080'
# App.cable = …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4 ruby-on-rails-5 actioncable

5
推荐指数
1
解决办法
3207
查看次数

CSRF InvalidAuthenticityToken 与 Rails 和 React

我无法让我的代码与 CSRF 令牌一起使用。

我有一个 axiosconfig 文件,我在其中设置 axios 并将其导出:

import axios from 'axios'

const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content')
const instance = axios.create({
  baseURL: 'http://api.domain.tld/v1/',
  headers: {
    'X-CSRF-Token': csrfToken
  }
});

export default instance
Run Code Online (Sandbox Code Playgroud)

以及我导入它的反应组件:

import axios from '../config/axios'
Run Code Online (Sandbox Code Playgroud)

在我提交的表单中,我解雇了这篇文章:

axios
  .post('/test', {
    longUrl: this.state.testValue
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Run Code Online (Sandbox Code Playgroud)

我的头看起来像这样: 在此输入图像描述

axios 发布的请求是这样的: 在此输入图像描述

请求标头和我的头中的 CSRF 令牌是相同的,但我的 Rails-app 响应错误 422(不可处理的实体)并且:

ActionController::InvalidAuthenticityToken
Run Code Online (Sandbox Code Playgroud)

是否有可能是这个问题:

  // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails reactjs axios

5
推荐指数
0
解决办法
2500
查看次数

libgdx为什么相机不跟随角色呢?

我是libgdx的新手,我读了一个教程(教程代码是我的基础).我有一个可以移动的角色,但相机不会跟随角色:(

这是我的WorldRenderer.java:

package com.evolutio.tee.view;

import com.evolutio.tee.model.Block;
import com.evolutio.tee.model.Tee;
import com.evolutio.tee.model.World;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;

public class WorldRenderer {

    private static final float CAMERA_WIDTH = 10f;
    private static final float CAMERA_HEIGHT = 7f;

    private World world;
    private OrthographicCamera cam;

    /** for debug rendering **/
    ShapeRenderer debugRenderer = new ShapeRenderer();

    /** Textures **/
    private Texture teeTexture;
    private Texture blockTexture;

    private SpriteBatch spriteBatch;
    private boolean debug = false;
    private int width; …
Run Code Online (Sandbox Code Playgroud)

java android libgdx

3
推荐指数
1
解决办法
6079
查看次数

rails 4如何配置ckeditor 4.1

我不想在我的Rails-App中使用CKEditor.

在我的gemfile中我添加了这一行

gem 'ckeditor', :git => 'https://github.com/galetahub/ckeditor.git'
Run Code Online (Sandbox Code Playgroud)

在我运行"bundle update"和"rails generate ckeditor:install --orm = active_record --backend = paperclip"后,我添加到我的application.js这一行:

//= require ckeditor/init
Run Code Online (Sandbox Code Playgroud)

在我看来,我添加了这一行:

<%= f.cktext_area :img, :ckeditor => {:toolbar => 'img', :customConfig => asset_path('ckeditor/config.js')} %>
Run Code Online (Sandbox Code Playgroud)

我创建了这个文件夹和文件:

/app/assets/javascripts/ckeditor
/app/assets/javascripts/ckeditor/config.js
/app/assets/javascripts/ckeditor/contents.css
Run Code Online (Sandbox Code Playgroud)

我的config.js看起来像这样:

CKEDITOR.editorConfig = function( config )
{
    config.toolbar_img = [
        { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] },
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的编辑器为何如此? CKEditor的

ruby ruby-on-rails ckeditor

3
推荐指数
1
解决办法
5133
查看次数

与Eloquent Laravel建立了很多关系

这个schmea我有两张桌子:

mysql> show columns from table_1;
+-------------+------------------+------+-----+---------------------+-----------
| Field       | Type             | Null | Key | Default             | Extra
+-------------+------------------+------+-----+---------------------+-----------
| id          | int(10) unsigned | NO   | PRI | NULL                | auto_incre
| id_world    | int(11)          | NO   |     | NULL                |
| key         | varchar(255)     | NO   |     | NULL                |
| name        | varchar(255)     | NO   |     | NULL                |
| description | varchar(255)     | NO   |     | NULL                |
| level       | int(11)          | NO   | …
Run Code Online (Sandbox Code Playgroud)

php mysql model laravel eloquent

2
推荐指数
1
解决办法
3483
查看次数

cancancan load_and_authorize_resource NameError

我使用CanCanCan,Devise和Rolify gem进行身份验证和权限管理.但是当我创建一个新控制器时,我收到了这条消息:

NameError in PanelController#dashboard
uninitialized constant Panel
Run Code Online (Sandbox Code Playgroud)

我的PanelController:

class PanelController < ApplicationController
  load_and_authorize_resource

  def dashboard
  end
end
Run Code Online (Sandbox Code Playgroud)

当我删除此行时:load_and_authorize_resource 路由工作.但我无需身份验证即可访问它.我需要PanelModel才能使用它吗?

我的AbilityModel是这样的:

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)

    alias_action :create, :read, :update, :destroy, :to => :crud

    if user.has_role? :admin
      can :manage, :all
    elsif user.has_role? :user
      can [:read], User
      can [:update, :edit], User do |account|
        account.email == user.email
      end
    else
      # can :read, :all
      can [:create, :new], User
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

昨天我的代码工作得很好,但今天我不知道为什么会出现这个错误.也许任何人都可以帮助我. …

ruby-on-rails cancan ruby-on-rails-4 cancancan

2
推荐指数
1
解决办法
808
查看次数

rails与has_many的关联错误

我尝试在用户和项目之间建立基本关联:

user.rb

class User < ActiveRecord::Base
  has_many :projects, foreign_key: 'owner_id'
  has_many :project_members, through: :project_members
end
Run Code Online (Sandbox Code Playgroud)

project.rb

class Project < ActiveRecord::Base
  has_many :project_members, dependent: :destroy
  has_many :users, through: :project_members
end
Run Code Online (Sandbox Code Playgroud)

project_member.rb

class ProjectMember < ActiveRecord::Base
  belongs_to :user
  belongs_to :project
end
Run Code Online (Sandbox Code Playgroud)

我的project_members表:

+----+------------+---------+
| id | project_id | user_id |
+----+------------+---------+
|  1 |          1 |       1 |
|  2 |          2 |       1 |
+----+------------+---------+
Run Code Online (Sandbox Code Playgroud)

和我的项目表:

+----+-------+----------+
| id | name  | owner_id |
+----+-------+----------+
|  1 | test1 |        1 …
Run Code Online (Sandbox Code Playgroud)

activerecord ruby-on-rails ruby-on-rails-4

2
推荐指数
1
解决办法
644
查看次数

将数据POST到服务器并使用redux处理响应的正确方法

我很反应和减少.

现在我想用redux进程重写我的post请求.

我当前的请求如下所示:

  _handleSubmit(event) {
    axios
      .post('/createUrl', {
        url: this.state.url
      })
      .then((response) => {
        this.setState({
          shortenInfos: response.data
        })
      })
      .catch((error) => {
        console.log(error);
      });

    event.preventDefault()
  }
Run Code Online (Sandbox Code Playgroud)

现在我创建了一个商店:

export default function url(state = 0, action) {
  switch (action.type) {
    case 'CREATE_URL':
      // maybe axios request?!
      return `${action.url}/test`
    case 'CREATED_URL':
      return `${action.url}/created`
    default:
      return state
  }
}
Run Code Online (Sandbox Code Playgroud)

所以我必须使用store.dispatch()?我应该让我的_handle提交这样的东西吗?

_handleSubmit(event) {
  axios
    .post('/createUrl', {
      url: this.state.url
    })
    .then((response) => {
      store.dispatch({
        type: 'CREATED_URL',
        url: response.data
      })
    })
    .catch((error) => {
      console.log(error);
    });

  event.preventDefault() …
Run Code Online (Sandbox Code Playgroud)

reactjs redux react-redux

0
推荐指数
1
解决办法
2903
查看次数