小编phi*_*hil的帖子

测试 has_one 关系?

我有一个对象

class User < ActiveRecord::Base
  has_one :subscription
end
Run Code Online (Sandbox Code Playgroud)

我有这个测试:

  it "should increment shipped count when item_shipped" do
    @user.attributes = @valid_attributes
    @user.save

    subscription = mock_model(Subscription)
    subscription.stub!(:item_shipped!)
    subscription.stub!(:user_id)
    @user.subscription = subscription

    lambda{@user.item_shipped!}.should change{@user.shipped_count}.by(1)
  end
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

1)
Spec::Mocks::MockExpectationError in 'User should increment shipped count when item_shipped'
Mock "Subscription_1113" received unexpected message :[]= with ("user_id", 922717357)
./spec/models/user_spec.rb:29:
Run Code Online (Sandbox Code Playgroud)

我不知道如何模拟这一点,而且我似乎找不到任何对此类事情的引用。

rspec ruby-on-rails

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

rails 3,paperclip(&formtastic) - 删除图像附件

我似乎无法找到所有组件中完整的示例.我很难删除图片附件

  1.   class Product
        has_many :product_images, :dependent => :destroy
        accepts_nested_attributes_for :product_images
      end
    
      class ProductImage
        belongs_to :product
        has_attached_file :image #(etc)
      end
    
    Run Code Online (Sandbox Code Playgroud)
  2. 视图

      <%= semantic_form_for [:admin, @product], :html => {:multipart => true} do |f| %>
        <%= f.inputs "Images" do %>
          <%= f.semantic_fields_for :product_images do |product_image| %>
            <% unless product_image.object.new_record? %>
              <%= product_image.input :_destroy, :as => :boolean, 
                 :label => image_tag(product_image.object.image.url(:thumb)) %>
            <% else %>
              <%= product_image.input :image, :as => :file, :name => "Add Image" %>
            <% end %>
          <% end %>
        <% end …
    Run Code Online (Sandbox Code Playgroud)

ruby-on-rails paperclip formtastic ruby-on-rails-3

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

Stimulus.js 加载部分的方式?

我们正在研究 Stimulus.js 与我们的 Rails6 应用程序一起使用,并不断突破概念壁垒,将我们的思维从 jQuery 转向 Stimulus。

例如:

在页面的一部分上,我们有一个按钮,当单击该按钮时,我们希望将内容加载到页面另一部分上的 div 中。在 jQuery 中,这很简单 - 响应click事件,将部分从 Rails 后端加载到该 div 中。

在刺激中,如何做到这一点?看起来一切都需要在一个大控制器中,以便按钮可以看到“目标 div”。所以本质上我们正在编写“页面”控制器,这看起来开销很大。此外,它扰乱了我们将页面分解为部分的方式,因为现在这些部分需要共享一个刺激控制器。

javascript stimulusjs

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

heroku - 我不想在本地安装postgres!

也许我错过了一些明显的东西,但是,我正在开发一个应用程序,现在我们想在heroku上运行.我使用mysql开发.我没有或想要在我的机器上安装postgres.

我在我的Gemfile中有这个:

gem 'mysql2', '~>0.2.6', :group => :development
gem "pg", :group => :production
Run Code Online (Sandbox Code Playgroud)

然而,当我在我的本地机器上进行捆绑安装时 - 在开发中 - 我看到了:

Installing pg (0.11.0) with native extensions /Users/smyp/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/installer.rb:533:in `build_extensions': ERROR:   Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/smyp/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Run Code Online (Sandbox Code Playgroud)

这是我所期望的,因为我本地没有postgres ......但为什么要尝试安装呢?!这不是打败团体的目的吗?

ruby-on-rails heroku bundler

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

admob找不到其他网络适配器 - iOS

这真让我抓狂.我的iOS应用程序中包含admob库.我还包含Millennial Media SDK文件.

Admob等文件

然而,当我跑步时,我收到了这些错误:

flags update: 0X000002
2013-10-15 16:58:52.621 LCApp[21403:a0b] <Google> Cannot find an ad network adapter with the name(s): (
GADMAdapterIAd
). Remember to link all required ad network adapters and SDKs, and set -ObjC in the 'Other Linker Flags' setting of your build target.
2013-10-15 16:58:52.621 LCApp[21403:a0b] <Google> Cannot find an ad network adapter with the name(s): (
GADMAdapterMillennial
). Remember to link all required ad network adapters and SDKs, and set -ObjC in the 'Other Linker Flags' …
Run Code Online (Sandbox Code Playgroud)

admob ios

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

TinyMCE w/Rails 6 和 webpacker - 无图标,turbolink

我们正在尝试使用 Webpacker(和 Stimulus)将我们的应用程序升级到 Rails 6。除了 TinyMCE 之外,一切都很顺利。我们有两个问题,我会在单独的问题中问他们。

我们安装 TinyMCE 使用

yarn add tinymce
Run Code Online (Sandbox Code Playgroud)

并且有版本5.3.0

在我们的刺激控制器标头中,我们有:

import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/silver';
import 'tinymce/skins/ui/oxide/skin.min';
import 'tinymce/skins/ui/oxide/content.min';

import 'tinymce/plugins/paste';
import 'tinymce/plugins/link';
Run Code Online (Sandbox Code Playgroud)

然后在控制器connect块中我们有:

  connect() {
    console.log('gonna reload');
    require.context(
      '!file-loader?name=[path][name].[ext]&context=node_modules/tinymce&outputPath=js!tinymce/skins',
      true,
      /.*/
    );
    tinymce.init({
      selector: '.tinymce',
      plugins: ['paste', 'link'],
      skin: false
    });
  }
Run Code Online (Sandbox Code Playgroud)

这是基本上有效的代码,除了在控制台中我看到:

VM40 application-68201fac0dcbbcb543e0.js:213771 GET https://xxx.ngrok.io/packs/js/icons/default/icons.js net::ERR_ABORTED 404 (Not Found)
VM40 application-68201fac0dcbbcb543e0.js:224775 Failed to load icons: default from url https://xxx.ngrok.io/packs/js/icons/default/icons.js
Run Code Online (Sandbox Code Playgroud)

我们需要另一个require.context来处理这些的加载吗?

tinymce ruby-on-rails

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