小编Jer*_*mas的帖子

Rails 4 + CSV:更改csv标头

我使用的仪器输出数据的CSV文件,但是我无法控制列名。我想在导入数据之前更改标题行(无需编辑原始CSV文件),以便可以使用以下代码将其导入数据库:

def self.import(file)
  CSV.foreach(file.path, headers: true) do |row|
    Foo.create! row.to_hash
  end
end  
Run Code Online (Sandbox Code Playgroud)

如何用自己的一个完全替换标题行?

csv ruby-on-rails

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

Vue.js显示从另一个组件调用一个组件

我有2个组件:

Vue.component('repo-button', {
  props:["check_in_id", "repo_id"],
  template: '#repo-button',
  methods: {
    fetchRepo: function() {
        url = window.location.href.split("#")[0] + "/check_ins/" + this.check_in_id + "/repositionings/" + this.repo_id + ".json"
        cl(url)
        cl(this)
        var that;
        that = this;

        $.ajax({
            url: url,
            success: function(data) {
                cl(data)
                that.showRepo();
            }
        })

    },
    showRepo: function() {
        // what do I put here to display the modal 
    }
  },
  data: function() {
  var that = this;
  return {

  }
}
});

Vue.component('repo-modal', {
    template: "#repo-modal",
    data: function() {
        return {
            status: …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

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

Rails:跳过 after_create

我有 2 个型号:

class User < ActiveRecord::Base
    has_one :client
end

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

我通常创建user第一个,并有一个过滤器,在创建后after_create创建。clientuser

after_create :create_client
Run Code Online (Sandbox Code Playgroud)

我有一个新的案例,其中存在,并且我想在已经存在的情况client创建。在这种情况下,当我创建时我想跳过过滤器。 user clientuserafter_create

我知道我需要after_create :create_client, unless: ____,但我不知道如何区分这一点。

ruby-on-rails callback after-create ruby-on-rails-4

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

离子:cordova-plugin-ionic 插件未安装时“离子插件添加”说已安装

我看过其他类似的问题,但仍然很困惑。当我使用 运行我的应用程序时ionic serve,我的控制台告诉我:

ionic-pro.min.js:1 the cordova-plugin-ionic plugin is not installed. Install it for better device information for runtime errors.
Run Code Online (Sandbox Code Playgroud)

但是当我运行时:

cordova plugin add cordova-plugin-ionic --variable APP_ID=app_id --variable CHANNEL_NAME=Production
Run Code Online (Sandbox Code Playgroud)

它说:

Plugin "cordova-plugin-ionic" already installed on android.
Plugin "cordova-plugin-ionic" already installed on browser.
Plugin "cordova-plugin-ionic" already installed on ios.
Run Code Online (Sandbox Code Playgroud)

我有一种感觉,这与我的其他问题之一有关,即 Ionic Pro 的 Deploy 服务未按预期工作。

这是我的环境:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.14.0
    ionic (Ionic CLI) : 3.14.0

global packages:

    cordova (Cordova CLI) : 7.0.1 

local packages:

    @ionic/app-scripts : 2.1.4
    Cordova …
Run Code Online (Sandbox Code Playgroud)

cordova ionic-framework

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

RSpec 要求我在测试通过之前打印对象

我有一个简单的模型测试,我正在测试我的验证,出于某种原因,我需要在测试通过之前打印对象。

以下测试失败(失败输出如下所示):

RSpec.describe HealthProfile, type: :model do
    let(:client) { create(:client) }
    let(:intro_hp) { create(:health_profile, :no_callbacks, :with_issues, client_id: client.id)}

    describe "should validate that" do

        it "diabetes is required in exit if present in intro" do
            exit_hp = build(:health_profile, :end, :no_callbacks, client_id: client.id)
            exit_hp.valid?

            expect(exit_hp.errors.keys).to include(:diabetic)

        end

    end
end

Failures:

  1) HealthProfile should validate that diabetes is required in exit if present in intro
     Failure/Error: expect(exit_hp.errors.keys).to include(:diabetic)

       expected [:weight_mindset_one, :weight_mindset_two, :weight_mindset_three] to include :diabetic
       Diff:
       @@ -1,2 +1,2 @@
       -[:diabetic]
       +[:weight_mindset_one, :weight_mindset_two, …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

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

使用 useSelector() 时找不到react-redux上下文值

我是新来的反应,并试图理解为什么我会看到这个错误:

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>
Run Code Online (Sandbox Code Playgroud)

应用程序.js

export default function App() {
  const selectedNumber = useSelector(selectChosenNumber) // This line causes the error

  function pickedNumberHandler() {
    console.log("called")
  }

  let screen = <StartGameScreen />;

  pickedNumberHandler()

  store.subscribe(pickedNumberHandler)

  return (
    <Provider store={store}>
      <LinearGradient colors={['#4e0329', '#ddb52f']} style={styles.rootScreen}>
        <ImageBackground
          source={require('./assets/images/background.png')}
          resizeMode="cover"
          style={styles.rootScreen}
          imageStyle={{opacity: 0.15}}
        >
          {screen}
        </ImageBackground>
      </LinearGradient>
    </Provider>
  );
}

const styles = StyleSheet.create({
  rootScreen: {
    flex: 1,
  }
})
Run Code Online (Sandbox Code Playgroud)

selectedNumberReducer.ts

export const chosenNumberSlice …
Run Code Online (Sandbox Code Playgroud)

reactjs redux

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