小编And*_*ndy的帖子

rails -v无法加载这样的文件 - rails/cli(LoadError)

Ubuntu 14.04.

所以一切都运行良好,我的终端打开了两个标签 - 一个标签在我的sebcoles项目上运行webbrick,另一个标签我用来克隆我的english_teacher repo.这一切都下载得很好,我改成了目录.

我会在这里粘贴所有内容 - 这一切都很清楚:

andrew:projects$ cd pinteresting
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /home/andrew/projects/pinteresting/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

ruby-2.1.5 is not installed.
To install do: 'rvm install ruby-2.1.5'

andrew:pinteresting$ rvm install ruby-2.1.5

Warning, new version of rvm available '1.26.11', you are using older version '1.26.10'.
You …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails rvm ruby-on-rails-4

8
推荐指数
2
解决办法
9797
查看次数

如何让 koa ctx.throw() 使用 application/json 而不是 text/plain

我为我的 koa 应用程序制作了一个自定义错误处理程序,它运行良好(除了一个症结点) - 使用 ctx.throw()意味着任何堆栈跟踪都被发送到服务器日志,并且任何自定义错误消息都会在响应中发送。

一个问题是,Content-Type标题是text/plain,但我真的需要它application/json

app.js

import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import logger from 'koa-morgan';

import authentication from './middleware/authentication';
import config from './config';
import errorHandler from './middleware/error-handler';
import notificationsRoutes from './routes/notifications';

const app = new Koa();

app.use(errorHandler);
app.use(bodyParser());
app.use(logger(config.logLevel));
app.use(authentication);
app.use(notificationsRoutes.routes());

export default app;
Run Code Online (Sandbox Code Playgroud)

error-handler.js

export default async (ctx, next) => {
  return next().catch(({ statusCode, message }) => {
    ctx.throw(statusCode, JSON.stringify({ message }));
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript koa

6
推荐指数
1
解决办法
4768
查看次数

如何在编辑表单中预先填充collection_check_boxes?

GitHub回购:https://github.com/Yorkshireman/mywordlist

我用谷歌搜索了这个.我确定有一种方法,可能需要在html选项哈希中使用一些代码,但我无法解决它.有任何想法吗?

当访问具有一个或多个类别的Word的_edit_word_form.html.erb部分时,"类别"复选框全部未选中,要求用户再次选择它们,即使他们不想更改类别.

:title和:description的文本字段已预先填充(谢天谢地).

_edit_word_form.html.erb:

<%= form_for(@word) do %>

  <%= fields_for :word, @word do |word_form| %>
    <div class="field form-group">
      <%= word_form.label(:title, "Word:") %><br>
      <%= word_form.text_field(:title, id: "new_word", required: true, autofocus: true, class: "form-control") %>
    </div>

    <div class="field form-group">
      <%= word_form.label(:description, "Definition:") %><br>
      <%= word_form.text_area(:description, class: "form-control") %>
    </div>
  <% end %>


  <%= fields_for :category, @category do |category_form| %>
    <% if current_user.word_list.categories.count > 0 %>
      <div class="field form-group">
        <%= category_form.label(:title, "Choose from existing Categories:") %><br>
        <%= category_form.collection_check_boxes(:category_ids, current_user.word_list.categories.all, …
Run Code Online (Sandbox Code Playgroud)

ruby forms checkbox ruby-on-rails ruby-on-rails-4

5
推荐指数
2
解决办法
2039
查看次数

量角器测试元素是否为空

<div id='messagesDiv'></div>

我想测试这个div元素是空的.

var messagesDiv = element(by.id('messagesDiv'));
expect(messagesDiv).to...
Run Code Online (Sandbox Code Playgroud)

我怎么做到这一点?

javascript protractor

5
推荐指数
2
解决办法
2424
查看次数

如何在控制器规范中禁用before_action?

我在我的控制器规范中使用了这个:

controller.class.skip_before_action
Run Code Online (Sandbox Code Playgroud)

具体来说,在这种情况下:

controller.class.skip_before_action:require_authorisation_to_view_materials

MaterialsController:

class MaterialsController < ApplicationController
  before_action :set_material, only: [:show, :edit, :update, :destroy]
  before_action :require_authorisation_to_view_materials, only: [:index, :show]


  def require_authorisation_to_view_materials # For Materials Page
    unless user_signed_in? && current_user.can_view_materials?
      redirect_to root_path, alert: "You are not authorised to view the Materials page."
    end
  end

  # GET /materials
  # GET /materials.json
  def index
    @materials = Material.all
  end

  # GET /materials/1
  # GET /materials/1.json
  def show
  end

  # GET /materials/new
  def new
    @material = Material.new
  end

  # GET /materials/1/edit
  def edit …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails rspec-rails ruby-on-rails-4

4
推荐指数
1
解决办法
4204
查看次数

无法访问另一个文件中的全局变量

我知道这已被问了很多次,但我已经检查了其他几个问题和答案,我仍然没有接近解决我的问题.

index.html的:

<!doctype html>
<html lang="en" ng-app="GitUserSearch">
  <head>
    <meta charset="utf-8">
    <title>Github user search</title>
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" href="bootstrap_css_overrides/bootstrap_overrides.css">
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-resource/angular-resource.js"></script>
    <script src="js/secrets.js"></script>
    <script src="js/app.js"></script>
    <script src="js/gitUserSearchController.js"></script>
  </head>

  <body ng-controller="GitUserSearchController as searchCtrl">
    <div class="container">
      <br>
      <form class="form-horizontal">
        <input type="text" ng-model="searchCtrl.searchTerm" ng-change="searchCtrl.doSearch()" ng-model-options="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0} }">
        <button class="btn btn-primary" ng-click="searchCtrl.doSearch()">Search</button>
      </form>
      <br>
      <ul class="list-group">
        <li ng-repeat="user in searchCtrl.searchResult.items">
          <img ng-src="{{user.avatar_url}}&s=50">
          <a ng-href="{{user.html_url}}">{{user.login}}</a>
        </li>
      </ul>
    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

JS/secrets.js:

githubToken = "longGithubTokenThatICannotShareHerePublicly"; …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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