Code Monkey home page Code Monkey logo

Comments (7)

9mm avatar 9mm commented on September 25, 2024

Also, How do I make it a v1 UUID instead of v4?

from activeuuid.

pyromaniac avatar pyromaniac commented on September 25, 2024

Regarding the first question - please, show your sources.
The second - try to redefine https://github.com/jashmenn/activeuuid/blob/master/lib/activeuuid/uuid.rb#L119 at your model.

from activeuuid.

9mm avatar 9mm commented on September 25, 2024

Migration:

class CreateSurveys < ActiveRecord::Migration
  def change
    create_table :surveys, :id => false do |t|
      t.references :employee, :null => false
      t.uuid :id, :primary_key => true
      t.datetime :expired_at
      t.timestamps
    end
    add_index :surveys, :id
  end
end       

survey.rb

class Survey < ActiveRecord::Base

  include ActiveUUID::UUID

  belongs_to :employee

  validates :employee, :presence => true  

end

from activeuuid.

pyromaniac avatar pyromaniac commented on September 25, 2024

Looks proper, except add_index :surveys, :id, primary keys in sql are indexed by default.
Still didn't get you. What is "MUL" then? Where did you see this?

from activeuuid.

pyromaniac avatar pyromaniac commented on September 25, 2024

Ah, got it. It is MUL because of add_index :surveys, :id. Just remove this line and it will become PRI

from activeuuid.

9mm avatar 9mm commented on September 25, 2024

That fixed it! Thanks! I saw the add_index line right on the documentation, as well as a few guides online. I don't know why everyone has that in their examples if it's not supposed to be on a primary key... hmm.

I'm sure you are busy but would you mind answering a few straggling questions of mine, just for the sake of learning?

  1. Do you think its important I try to override the v4 to be v1? I read on the issues here that v4 isn't as secure. The purpose of me using a UUID is because each hour I need to email surveys out where a user will click a link. I don't want the link in the email to be sequentially numbered as a normal key so people cant find out other ID's. I will also be looking up surveys by UUID so that is important as well.
  2. Is there any particular way I can remove dashes (for the URL). I'd rather not have them when people see the URL. Currently I'm just using the code below. I'm not sure if it's acceptable to use that, and then to convert back, maybe add the dashes back in the correct spot. Or.. if there is something magic about this where my assumption would be foolish.
def token                                
  id.hexdigest                           
end                                      

def self.id_from_token(token)            
  UUIDTools::UUID.parse_hexdigest(token) 
end                                      

Thanks!

from activeuuid.

pyromaniac avatar pyromaniac commented on September 25, 2024

If you ask me - there is no indication to use activeuuid at all. In your place, I would make a usual autoincrement id and additional token field with uniq index to store hex values. And use simply before_save to generate this token.

I do not know about the difference between v1 and v4, but you can use whatever you need with http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html

from activeuuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.