Comments (7)
Also, How do I make it a v1 UUID instead of v4?
from activeuuid.
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.
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.
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.
Ah, got it. It is MUL because of add_index :surveys, :id
. Just remove this line and it will become PRI
from activeuuid.
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?
- 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.
- 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.
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)
- How to add uuid primary key column to the existing table in migration script
- mysql2 adapter not loaded when railtie runs HOT 3
- Problems with the search by id
- Primary key column_hash is binary != :uuid HOT 2
- Default primary key value is incompatible with accepts_nested_attributes_for HOT 1
- has_one children being updated with parent record HOT 1
- Finding non-existent record in assocation causes Cannot visit UUIDTools::UUID with Rails 3
- to_yaml support & yaml_db clean export
- Still Maintained? HOT 1
- Backwards compatibility with integer IDs? HOT 8
- 0.6.1 patch release? HOT 2
- PostgreSQL: TypeError: can't cast UUIDTools::UUID to uuid HOT 5
- you can't redefine the primary key column 'id'. HOT 3
- Rails 5 compatibility HOT 8
- SQL (MySQL) errors in complex arel queries HOT 1
- No Changelog
- Rails 5 issues HOT 5
- schema.rb not being generated correctly after migration HOT 4
- .find not accepting string containing UUID HOT 1
- .includes association with uuid not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activeuuid.