This is my authentication file:
module Command
class AuthenticateUser
prepend SimpleCommand
...
end
end
And then I made a test with this:
require 'rails_helper'
RSpec.describe Command::AuthenticateUser do
...
end
When I ran the test, got this error:
# --- Caused by: ---
# NameError:
# uninitialized constant Command
# ./spec/commands/authenticate_user_spec.rb:3:in `<top (required)>'
Not sure where is the problem with my code, could you give some suggestions Thanks in advance.
Try this:
class AuthenticateUser
prepend SimpleCommand
...
end
&
require 'rails_helper'
describe AuthenticateUser do
...
end
Related
I am using Active Storage to store images but and doesn't work for a specific model, first an example with a working model:
class GalleryImage < ApplicationRecord
has_one_attached :image
end
In this case everything works well, here is the console output:
2.7.0 :006 > ::GalleryImage.new.image
=> #<ActiveStorage::Attached::One:0x0000557a5b57b1f8 #name="image" ...>>
But, I have another model called AppSetting like this:
class AppSetting < ApplicationRecord
def hola
'hola'
end
has_one_attached :gimmick
def adios
'adios'
end
end
And, when I try it in the rails console:
2.7.0 :006 > ::AppSetting.new.hola
=> "hola"
2.7.0 :007 > ::AppSetting.new.gimmick
Traceback (most recent call last):
1: from (irb):7
NoMethodError (undefined method `gimmick' for #<AppSetting:0x0000560cb955b470>)
2.7.0 :008 > ::AppSetting.new.adios
Traceback (most recent call last):
2: from (irb):7
1: from (irb):8:in `rescue in irb_binding'
NoMethodError (undefined method `adios' for #<AppSetting:0x0000560cb94241d8>)
As you can see, the first method (hola) works well, but I'm getting NoMethodError (undefined method... error message for the next methods.
any help? please.
Currently trying to install rolify to my rails application
Followed the steps on github and am getting the following error after running rails db:migrate
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rolify-5.2.0/lib/rolify.rb:30: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3/lib/active_record/associations.rb:1826: warning: The called method `has_and_belongs_to_many' is defined here
rake aborted!
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'
Caused by:
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Within the migration file ammend the version number like so
class RolifyCreateRoles < ActiveRecord::Migration[6.0]
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
create_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
add_index(:roles, [ :name, :resource_type, :resource_id ])
add_index(:users_roles, [ :user_id, :role_id ])
end
end
I Have code and using rails version 5.1.1
Code file routes.rb :
Rails.application.routes.draw do
root "movies#index"
resources :movies, only: [:index, :create]
end
Code file app\controllers\movies_controller.rb
class MoviesController < ApplicationController
def index
end
def create
url = params[:url]
#links = GoogleDrive.list_link_videos url
render :index
end
end
When I run Then It is show error "uninitialized constant MoviesController"
Can you help me ?
Thanks
This is a minimal example to show a very weird thing when using sbt run. Trying to make the example any smaller, then the problem does not arises any more. Am I missing something or is this a bug or sbt?
build.sbt
name := "testsbt"
version := "1.0"
scalaVersion := "2.11.8"
project/build.properties
sbt.version = 0.13.13
src/main/scala/application/Test.scala
package application
import java.io._
case class Page(items: List[Item])
case class Item(text: String)
object Test extends App {
val page = Page(List(Item("item1")))
val filename = "./page.obj"
val oos = new ObjectOutputStream(new FileOutputStream(filename))
try oos.writeObject(page)
finally oos.close()
println("read: " + new ObjectInputStream(new FileInputStream(filename)).readObject())
}
executing this with sbt run fails:
$ sbt run
[error] (run-main-0) java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.List$SerializationProxy to field application.Page.items of type scala.collection.immutable.List in instance of application.Page
however, executing sbt package and running from it works:
$ sbt package
$ scala -cp target/scala-2.11/testsbt_2.11-1.0.jar application.Test
read: Page(List(Item(item1)))
I managed to compile the mruby code adding the mrubygem - mruby-require from https://github.com/mattn/mruby-require
However when I try to call the require './' I get an error. Below is my code:
inc.rb
def test(a, b)
print "Inside the include->test(..)"
return a+b
end
test1.rb
require 'inc.rb'
def helloworld(var1)
print 'hello world ' + var1 + ". Test number = " + test(4, 5)
end
helloworld('test')
When I execute test1.rb I get this error from mruby:
NoMethodError: undefined method 'puts' for main
After some analysis I found out the 'puts' is not working with mruby. Infact after adding mruby-require gem, no ruby code gets execute. Do I need to add any dependency with mruby-require?
Can someone help me please?
Update: Pasting the content of build_config.rb as requested. I have removed the lines which are commented.
build_config.rb
MRuby::Build.new do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# adding the mruby-require library
conf.gem 'mrbgems/mruby-require'
conf.gembox 'default'
end
MRuby::Build.new('host-debug') do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.gembox 'default'
conf.cc.defines = %w(ENABLE_DEBUG)
conf.gem :core => "mruby-bin-debugger"
end
The following quote is from its README.md:
When mruby-require is being used, additional mrbgems that appear after mruby-require in build_config.rb must be required to be used.
This is from your build_config.rb:
conf.gem 'mrbgems/mruby-require'
conf.gembox 'default'
The default gembox contains mruby-print. So either require mruby-print or preferably swap the lines to make it a built-in gem (the default behavior without mruby-require).