seed

How to avoid the validation, callbacks and 'attr_accessible' effects during the seeding process using Ruby on Rails 3?

淺唱寂寞╮ 提交于 2019-12-03 20:31:27
问题 I am using Ruby on Rails 3 and I am trying to seed data in my application database. In 'RAILS_ROOT/models/user.rb' I have: class User < ActiveRecord::Base attr_accessible #none validates :name, :presence => true validates :surname, :presence => true validates :email, :presence => true end In 'RAILS_ROOT/db/seeds.rb' I have: # Test 1 User.find_or_create_by_email ( :name => "Test1 name", :surname => "Test1 surname", :email => "test1@test1.test1" ) # Test2 User.find_or_create_by_email ( :name =>

What is random seed about?

≯℡__Kan透↙ 提交于 2019-12-03 17:33:06
For example the code below. It has a random class. However it always produce the same output everywhere . In this case which item is the seed? source: link import java.util.Random; public class RandomTest { public static void main(String[] s) { Random rnd1 = new Random(42); Random rnd2 = new Random(42); System.out.println(rnd1.nextInt(100)+" - "+rnd2.nextInt(100)); System.out.println(rnd1.nextInt()+" - "+rnd2.nextInt()); System.out.println(rnd1.nextDouble()+" - "+rnd2.nextDouble()); System.out.println(rnd1.nextLong()+" - "+rnd2.nextLong()); } } 42 is the seed, as the very same Javadoc says. So

Seed images in heroku with paperclip

六眼飞鱼酱① 提交于 2019-12-03 17:23:20
When I run heroku run rake db:seed I get Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/image20130219-2-1gk1yip.png[0]' Command :: composite -gravity Center /app/public/media/watermark.png "/tmp/image20130219-2-1gk1yip.png[0]" -resize "1x1<" "/tmp/image20130219-2-1gk1yip.png20130219-2-1ng5f6c[0]" Command :: file -b --mime '/tmp/image20130219-2-1gk1yip.png20130219-2-1ng5f6c' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/image20130219-2-1gk1yip20130219-2-t3caqg.png20130219-2-1ng5f6c[0]' Command :: convert "/tmp/image20130219-2-1gk1yip20130219-2-t3caqg.png20130219-2

Using Paperclip within seeds.rb

假如想象 提交于 2019-12-03 10:16:52
Let's says I have the following entry in my seeds.rb file : Image.create(:id => 52, :asset_file_name => "somefile.jpg", :asset_file_size => 101668, :asset_content_type => "image/jpeg", :product_id => 52) If I seed it, it tries to process the image specified, I get this error : No such file or directory - {file path} etc... My images are backed up, so I don't really need to create them; but I need the record though. I can't comment the paperclip directive in my model; then it works; but I guess there might be another solution. Is there another pattern to follow in order to accomplish it ? Or a

How to create SecurityStamp for AspNetUser in ASP .NET MVC 5

限于喜欢 提交于 2019-12-03 09:48:23
When I create user by Register action whe application is running the application user gets SecurityStamp. When I add user by: if (!context.Users.Any()) { System.Diagnostics.Debug.WriteLine("INSIDE"); var hasher = new PasswordHasher(); try { var users = new List<ApplicationUser> { new ApplicationUser{PasswordHash = hasher.HashPassword("TestPass44!"), Email = "informatyka4444@wp.pl", UserName = "informatyka4444@wp.pl"}, new ApplicationUser{PasswordHash = hasher.HashPassword("TestPass44!"), Email = "informatyka4445@wp.pl", UserName = "informatyka4445@wp.pl"} }; users.ForEach(user => context.Users

Restricting URLs to seed URL domain only crawler4j

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want crawler4j to visit pages in such a manner that they belong to domain in seed only. There multiple domains in seed. How can I do it? Suppose I am adding seed URLs: www.google.com www.yahoo.com www.wikipedia.com Now I am starting the crawling but I want my crawler to visit pages (just like shouldVisit() ) only in above three domains. Obviously there external links, but I want my crawler to restrict to these domains only. Sub-domain, sub-folders are okay, but not outside these domains. 回答1: If you are trying to restrict the

How to seed data when using Model First approach?

自古美人都是妖i 提交于 2019-12-03 08:40:18
问题 So I am learning MVC3 and EF4. I tried the code first method but it was too confusing for me.. I can create the classes no problem, but the hard part comes when dealing with foreign keys and the relationships between each other. But I've gone with model first. This way I can visually design it and see where the relationships are. After my model is create, it creates a SQL for me which I execute against my SQL Express database. Done, and done. Now I want data in my tables. Of course I can just

How to start writing Gnome Shell extensions

…衆ロ難τιáo~ 提交于 2019-12-03 03:37:55
问题 I have found it's very hard to find documentation about Gnome Shell Extensions. I found some bits on Gnome Wiki (and it's first-level links), but it's not much: http://live.gnome.org/GnomeShell/Extensions The problem here is GJS and it's bindings. Absolutely no documentation, got lot's of SIGSEGVs, binding is just not ready (GLib, Gio and others). The only working one is unofficial documentation generated from GIR for Seed JavaScript implementation: http://roojs.org/seed/gir-1.2-gtk-2.0/seed/

C++ equivalent of new Random(seed) in C#

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When we are using a random number generator in C#, we can define a variable like private Random _rndGenerator; in a class and then call _rndGenerator = new Random(seed); correctly in the constructor of the class. My question is: What is a C++ equivalent of such a definition (i.e. an RNG in a class). I think it is not a correct approach to use srand((unsigned int)seed); right? 回答1: C++11 has much more powerful random-number generation facilities. Here's an example: #include <random> #include <functional> std::size_t get_seed(); // whatever is

Rails how to create data schema seed data

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to auto generate a seed data file and create seed data like what you would see in Laravel in below link? Laravel Database Migrations & Seed I've seen some timestamped files created under db folder of Rails on another app with timestamp which had seed data included. What would be good approach to create this? 回答1: I suggest you to use the combination of Fabrication gem and Faker . Fabrication allows you to write a pattern to build your objects and Faker gives you fake data like names, emails, phone numbers and so on. This is