小编mat*_*fel的帖子

编译器无法生成可执行文件.(RuntimeError)

我最近升级到OS Mountain Lion.我正在处理的项目需要gem sys-proctable作为依赖项,但是当我运行时,bundle install我得到:

Fetching gem metadata from https://rubygems.org/.........
.
.
.
Installing sys-proctable (0.9.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for rb_pid_t in ruby.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby …
Run Code Online (Sandbox Code Playgroud)

ruby xcode rubygems ruby-on-rails

21
推荐指数
5
解决办法
4万
查看次数

在rails中跳过JSON格式生成脚手架

当您使用命令生成rails脚手架时,rails g scaffold Thing有任何方法可以避免令人讨厌

respond_to do |format|
  format.html # index.html.erb
  format.json { render json: @things }
end
Run Code Online (Sandbox Code Playgroud)

你控制器里的东西?

我正在尝试在Rails上教一个类,我想首先让它们生成一个脚手架,但是所有json格式化它都比它需要的要复杂得多.如果他们能够生成一个创建这样的控制器的脚手架,我会更高兴:

class ThingsController < ApplicationController

  def index
    @things = Thing.all
  end

  def show
    @thing = Thing.find(params[:id])
  end

  def new
    @thing = Thing.new
  end

  def edit
    @thing = Thing.find(params[:id])
  end

  def create
    @thing = Thing.new(params[:thing])
      if @thing.save
        redirect_to @thing, notice: 'Thing was successfully created.'
      else
        render: "new" 
      end
    end
  end

  def update
    @thing = Thing.find(params[:id])
      if @thing.update_attributes(params[:thing])
        redirect_to @thing, notice: 'Thing …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails scaffolding ruby-on-rails-3

16
推荐指数
2
解决办法
4723
查看次数

rvm install 1.9.3失败

我尝试重新安装ruby,xcode和其他一些东西,因为我不断收到这些奇怪的C编译器错误.在某些时候我的所有红宝石都被卸载了,所以我在开始时就开始了...

rvm get head && rvm reload
rvm install 1.9.3
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

No binary rubies available for: downloads/ruby-1.9.3-p327.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p327, this may take a while depending on your cpu(s)...
ruby-1.9.3-p327 - #downloading ruby-1.9.3-p327, this may take a while depending on your connection...
ruby-1.9.3-p327 - #extracted to /Users/mgriffel/.rvm/src/ruby-1.9.3-p327 (already extracted)
ruby-1.9.3-p327 - #configuring
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --enable-shared --disable-install-doc --prefix=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p327 --with-opt-dir=/Users/mgriffel/.rvm/usr', …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails rvm

7
推荐指数
1
解决办法
4485
查看次数

CanCan和多态关联(急切加载错误)

我正在尝试定义用户基于关联模型上的列访问内容的能力(类似can :read, Step, 'steppable' => {published: true}),问题是它是一个多态关联,因此无法找到可步进表,因为它不存在。

我有步骤,每个步骤都有一个步骤(演讲,测验或其他操作)。我需要一个有效的记录查询,它将起作用。我试过了:

Step.includes(:steppable).where('steppable' => {published: true})

Step.joins(:steppable).where('steppable' => {published: true})

但是两者都会导致 ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :steppable

模型看起来像这样:

class Step < ActiveRecord::Base
   ...
   belongs_to :steppable, polymorphic: true, dependent: :destroy
   ...
end
Run Code Online (Sandbox Code Playgroud)

class Lecture
   ...
   has_one :step, as: :steppable, dependent: :destroy
   ...
end
Run Code Online (Sandbox Code Playgroud)

注意:我想对相关模型不了解,为了使其能够使用CanCan来获取记录,必须使用数据库列来完成(请参见github.com/ryanb/cancan/wiki/defining-abilities

activerecord ruby-on-rails cancan

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