vendredi 1 septembre 2017

BCrypt::Errors::InvalidHash (invalid hash) Devise 1.5.4 Rails 2.2.5

we are using the following in devise.rb

config.encryptor = :bcrypt

We wanted to change this to

config.encryptor = :authlogic_sha512

Also written code to decrypt old password and hash it to new one when signing in (inside session controller)

However, after updating the password, it gives an error

BCrypt::Errors::InvalidHash (invalid hash):

This error comes at random places if I comment out the original point of the error. So I suppose there is something wrong with either the devise configuration OR with the user.rb model.

The user model has the following line:

devise :database_authenticatable, :registerable, :confirmable,
     :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:auth0, :google_oauth2]

Any idea what could be the issue here? thanks in advance.

Rails variable data is changing

I have two tables that has many to many association

students projects

connected through the table student_projects

student = Student.find(1)
old_projects = student.projects

#Now Iam calling function that will create projects
create_projects

student = Student.find(1)
new_projects = student.projects
newly_added_projects = new_projects - old_projects

Old projects were empty,new_projects weren't

I put the logger statement before creating and after line(new_projects = students.projects), then I can see the difference.

But when I put the logger statement only after line (newly_added_projects = new_projects - old_projects) inspecting old_projects, new_projects, newly_added_projects

then old_projects is equal to new_projects

Can someone help me in this

mercredi 30 août 2017

Using Zeus for Rails auto-reloading, how do I include classes in extra subfolders?

I'm working on a large Rails 3.2 project. I use Zeus (and sometimes Guard) to auto reload rails so the tests run faster. However, when running certain tests, I get uninitialized constant errors.

It appears that Zeus doesn't like the fact that I've added some subfolders for organizational purposes.

To be specific, under app/models I added a devices subfolder and under that I have other folders that correspond to the namespace of a device.

For example, I might have: app/models/devices/amazon/alexa.rb which would contain the class: Amazon::Alexa. (not an actual example, but indicative of the naming and folder constructs).

I've added the app/models/devices folder to the load path in application.rb:

config.autoload_paths += [ Rails.root.join("app", "models", "devices") ]

This works when I run the Rails app. It also works if I run the specs directly (rspec ...)

But it fails to load constants when I run via Zeus or Guard.

Any suggestions on how to properly configure Zeus/Guard or Rails/Rspec so the load path works and the classes & constants are loaded correctly?

Thanks!

Start Stripe payments after customer information saved [RAILS 5]

I'm building an payment feature to my application and i'm stuck.

So i am on the first checkout page (fill in shipping address and billing address which are part of my Customers model/controller). What i want is when i click on 'submit / go to checkout' that the customer information gets saved AND i start the procedure of checking out with iDeal. As described here (Stripe API -- Stripe API reference ) to accept iDeal payments.

Currently i have this in my StripesController but i can also delete this and the functionality to the Customers controller if need be:

class StripesController < ApplicationController

def create_source
  create_stripe_source
end

private

def create_stripe_source
    Stripe.api_key = "pk_test_asdasn123jlkasdlkmcfake"

    Stripe::Source.create(
      type: "ideal",
      amount: 1000,
      currency: 'eur',
      owner: {
        name: 'John Wicked',
      },
      redirect: {
        return_url: root_url
      }
    )
end
end

I have this in my '_form' as used in my Customers#New

= form_for :customer do |f|
  = f.first_name
  = f.submit

Help would save me big time and thus be much much appreciated.

mardi 29 août 2017

NameError in ArticlesController#create undefined local variable or method `article_params' for #

I am getting this error when I create my articles:

error: NameError in ArticlesController#create undefined local variable or method `article_params' for # Did you mean? article_path

image of error : enter image description here

my code :

class ArticlesController < ApplicationController

   def new
     @article = Article.new 
   end
   def create
  @article = Article.new(article_params)


 if  @article.save
  flash[:notice] = "Article was submitted succsefully"
  redirect_to (@article)
else
   render :new
 end 

    private 
    def article_params 
       params.require(:article).permit(:title, :description)

    end





   end




end 

syntax error, unexpected '=', expecting keyword_end flash [:notice] = "Article was submitted succsefully"

I have this error which is not letting me look at articles that are created

here are my codes article_controller.rb file:

class ArticlesController < ApplicationController

   def new
     @article = Article.new 
   end
   def create
  @article = Article.new(article_params)


 if  @article.save
  flash [:notice] = "Article was submitted succsefully"
  redirect_to_article_path(@article)
else
   render :new
 end 
end 
    private 
    def article_params 
       params.require(:article).permit(:title, :description)

    end





   end




end 

ask me for any other files if you need them

sending Sha256 hash as a URL param as signature for Rails request data

I've noticed that when i send a url like this:

http://localhost:3000/register/register_user/?sig=zaQ/876CwJMEEmrJqAOYHyEKBXy2s03NDmk+3FsXPr4=

what comes through when I use it to compare to the expected result using params[:sig] in the controller is this:

zaQ/876CwJMEEmrJqAOYHyEKBXy2s03NDmk 3FsXPr4=

For some reason the '+' sign that was in the url at the 9th character from the end of the string has been converted to a space.

Not sure why that happens, whether it only happens with + signs or what.

The result returned by Digest::SHA256.base64digest(data) has this plus sign so my validation of the signature is failing.

What's the best way to fix this? Will it suffice in the general case just to convert '+' signs into spaces before the comparison or is the re some less ugly way to address?