danielpclark/rutie

NoMethodError in rails console

Dobermensch opened this issue · 4 comments

Here's my lib.rs:

#[macro_use]
extern crate rutie_serde;

use rayon::prelude::*;
use rutie::{class, Class, Object, Thread, RString, VM};

use rutie_serde::{ruby_class, rutie_serde_methods};
use serde_derive::{Deserialize, Serialize};


class!(ExampleRustLib);

rutie_serde_methods!(
    ExampleRustLib,
    _itself,
    ruby_class!(Exception),
   
    fn pub_hello() -> String {
        format!("Hello")
    }
);

#[no_mangle]
pub extern "C" fn Init_example_rust_lib() {
    rutie::Class::new("ExampleRustLib", None).define(|itself| {
        itself.def_self("hello", pub_hello);
    });
}

Here's my config/application.rb

require_relative 'boot'

require 'rails/all'
require 'rutie'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module RutieTest
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 6.0

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
    Rutie
    .new(:example_rust_lib, lib_path: 'target/release')
    .init('Init_example_rust_lib', 'example_rust_lib')
  end
end

Did cargo build --release && then rails s then rails c

Here's the output:
rutie_error

It was working before. I removed the Rutie code from application.rb to test things. It broke as expected. However, after adding the code back, restarted the app, rebuilt rust lib, now getting this new error.

Any suggestions?

Have you run cargo clean ? It removes the target folder. If the target folder sticks around you end up with all of the old build artifacts from when the code wasn't as it should be.

Yeap I did. Could it have something to do with running this on WSL ?

@Dobermensch It looks like you're using def_self rather than def so the method is on the class rather than the instance of the class. The README's use of it shows new is never called when using def_self. def_self is like:

class ExampleRustLib
  def self.hello
  end
end

Oh goodness me... Thank you very much