I am getting error when using hook in Rails application - ruby-on-rails

Can some explain what these two line is used for in the application.html.haml file. I am using Rails 6
= hook(:stylesheet_includes, self) do
#{yield :stylesheet_includes}
I am getting the following error
undefined method `hook' for #<#<Class:0x000000000bb090b8>:0x0000000007886f10>

Related

Having trouble to insert local image into the seeds.rb file in Rails

I am tring to insert an image in my assets directory into my seeds.rb file by using the following code: (I found this code online)
Product.destroy_all
p1=Product.create! name: "Peachy Oolong", price:15.00, stock:50, description: "Dong Ding Oolong Tea with Shizuoka 🍑, we call it the best combo for ice cream. "
p1.avatar.attach(io: File.open(Rails.root.join('app/assets/images/peach.JPG')),filename: 'peach.JPG')
On the console, it shows the following error:
NoMethodError: undefined method `avatar' for #<Product:0x000000013a508210>
/Users/dizhang/.rvm/gems/ruby-2.7.0/gems/activemodel-5.2.6/lib/active_model/attribute_methods.rb:430:in `method_missing'
How do I fix this NoMethodError?

undefined method `+' for nil:NilClass in sample saml application

Trying to follow the setup here to create a simple SAML application (full project I got here).
I went through and did the setup
bundle install
rails s
This went fine, but when I navigate to
http://localhost:3000/
I get hit with
NoMethodError in SamlController#init
undefined method `+' for nil:NilClass
Extracted source (around line #9):
def init
request = OneLogin::RubySaml::Authrequest.new
direct_to(request.create(saml_settings))
end
def consume
I added some logging to check nil status of request and saml_settings but that seems to return false for both of them
puts request.nil?
puts saml_settings.nil?
Error trace:
Processing by SamlController#init as HTML
false
false
Created AuthnRequest: <samlp:AuthnRequest AssertionConsumerServiceURL='http://localhost:3000/saml/consume' ID='_394fa0a0-f313-0135-85a4-6a0001e18280' IssueInstant='2018-02-13T17:42:45Z' Version='2.0' xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol'><saml:Issuer>http://localhost:3000/saml/consume</saml:Issuer></samlp:AuthnRequest>
Completed 500 Internal Server Error in 15ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `+' for nil:NilClass):
app/controllers/saml_controller.rb:9:in `init'
(Note: the error is line 5, it says line 9 for me because of debug logging I added)
I'm not too sure what else it could be, not sure what method it can't find and what is nil?
I have never messed with ruby stuff, but from my initial looks I'm not sure where the nil is coming from, the logs show the request being created so not sure. Any help would be appreciated, thanks!
Firstly I think you're using a pretty old ruby-saml gem version. That might be the problem.
I haven't tested your code, but it seems to me that you forgot to set idp_sso_target_url in your settings, and apparently that's the only place it can throw the exception you got. https://github.com/onelogin/ruby-saml/blob/v1.1.2/lib/onelogin/ruby-saml/authrequest.rb#L39
Posting the answer here, turns out that i was using a metadata url for the OKTA_METADATA environment variable.
Had to modify
settings = idp_metadata_parser.parse(ENV['OKTA_METADATA'])
to
settings = idp_metadata_parser.parse_remote(ENV['OKTA_METADATA'])
where
OKTA_METADATA=http://blahblahblah.com/metadata

prerendering in react_on_rails app is throwing error

Whenever I switch prerendering to true for my react component in my rails view I'm getting this error
undefined local variable or method `e' for ReactOnRails::ServerRenderingPool::Exec:Class
I've found on the shakacode site that there's a typo in lib/react_on_rails/server_rendering_pool/exec.rb
but I don't know how to access that file - it's nowhere in my directory - am I completely missing something here?
This has been fixed already on: https://github.com/shakacode/react_on_rails/pull/1020

Block Chain Ethereum Error NoMethodError: undefined method `keys' for nil:NilClass

I am integrating Block chain with my Rails App , so I am using Ethereum gem
to host the data to the blockchain.
I am getting the below error when i am trying to implement Ethereum to my Rails App.
I am using the following gem enter link description here
While i am trying the following command
init = Ethereum::Initializer.new("#{ENV['PWD']}/SimpleNameRegistry.sol", client)
I am getting the below error
NoMethodError: undefined method `keys' for nil:NilClass
when I try to debug inside the gem I received the following error code in the below line.
Error Line:
sol_output = #client.compile_solidity(#file)
Error Code:
{"jsonrpc"=>"2.0", "error"=>{"code"=>-32600, "message"=>"EOF"}}
Please help me to get out of this error as I am stuck with this.
Please also suggest me with an easy implementation of block chain with rails.

Net::IMAP uninitialized constant error

I really don't know where to start with this one, but I am (first time) using Net::IMAP and I am getting the following error:
NameError in EmailsController#connect
uninitialized constant Net::IMAP
Extracted source (around line #4):
2
3 def connect
4 imap = Net::IMAP.new('outlook.office365.com')
5 imap.authenticate('LOGIN', '**#**.com', '**')
6 imap.examine('INBOX')
7 #emails = imap.search(["RECENT"])
Not really sure what is going on here, I don't have to have anything in my Gemfile.rb? Or anything else before I set the imap variable?
You need to require 'net/imap' at the top of the file to bring Net::IMAP into scope.

Resources