Activity Graph

Page 1 of 1


[01:42:48] d08z: has joined #RubyOnRails
[01:44:04] d08z: hi, lets say i have a Country model and a City model, which belongs_to country... What happens if i do this: c = City.new; c.country_id = 42; <-- does assigning the foreign key will automagically create the c.country association?
[01:47:17] d08z: ...im on my cell
[01:47:30] d08z: on the bus
[01:47:56] d08z: well do you knwo the answer?
[01:48:23] d08z: ok and you wont tell me because ... ?
[01:49:04] d08z: im willing to pay in bitcoins
[01:53:52] d08z: Quit: Page closed


[11:33:04] d08z: has joined #RubyOnRails
[11:34:35] d08z: hi, how can i ensure that my belongs_to association exists in the databas? validates_presence_of does not work (you could put a newly created object plus there is no guarantee the object is still in the database when saving)
[11:35:56] d08z: universa1: isnt there a "validates_existence_in_db" kind of validator?
[11:36:25] d08z: so how can i "enforce" referential integrity BEFORE saving
[11:37:56] d08z: has anyone ever used the "validates_existence" gem?
[11:39:06] d08z: ok, lets say nothing can be deleted...
[11:40:18] d08z: either im doing something really wrong or i dont understand because i thought it would be a very simple common and task to validate the existence :(
[11:42:37] d08z: exemple: City.country = Country.new <-- validate_presence_of will return true
[11:42:58] d08z: but the country is not in the database
[11:44:02] d08z: validates_presence_of does not work either
[11:44:07] d08z: i could put a fake id
[11:45:06] d08z: ok so what you guys are telling me is "there is no way to validate that an objects exists in the database before saving it"
[11:45:49] d08z: so hit the database and wait for an exception
[11:46:51] d08z: so, save the object and wait for a foreign key error
[11:49:37] d08z: im trying my best to ask my question but im not sure how to correctly ask it :(
[11:50:03] d08z: seems so trivial
[11:50:48] d08z: ok lets say i have a Country and a City model, country has_many cities and City belongs_to country
[11:51:28] d08z: how can i validate (IN RAILS) that the associated country (city.country) exists in the database when saving
[11:52:13] d08z: yes thats what i did but i thought there would be a "rails way"
[11:53:08] d08z: the equivalent of foreign_key() in django
[11:54:39] d08z: ensures the relation is not null, has an id, is not new and hits the database with model.exists(foreign_key_id) before saving
[11:56:07] d08z: well then how can you intercept the error
[11:56:58] d08z: ok well thanks for your help
[12:16:56] d08z: Quit: leaving


[15:02:38] d08z: has joined #ruby
[15:03:46] d08z: hi, what would be the best way to "return object method value if the method exists else return a default value", something like puts x.blah() || "default" (if x has no "blah" method)
[15:05:18] d08z: hxegon: i should add "using only one line"
[15:07:08] d08z: hxegon: is there a more elegant way ala hash.fetch("x", "default_x")
[15:09:49] d08z: hxegon: ok thanks
[15:10:23] d08z: Quit: leaving


[17:41:18] d08z: has joined #RubyOnRails
[17:43:24] d08z: i have a file "lib/blah.rb" and inside "blah.rb" there is a "require_relative foo.rb" ... now, to use my lib in my controller i "require_dependency lib/blah". How can i ensure BOTH files are "reloaded" when i update the code in dev mode?
[17:45:08] d08z: tubbo: i dont have to, but, putting it in the autoload_paths does not reload the code on each request
[17:46:28] d08z: i do use require_dependency
[17:46:34] d08z: i did read that guide
[17:47:06] d08z: the "blah.rb" library _IS_ reloaded on each request but NOT the "foo.rb" one
[17:47:37] d08z: (foo.rb is "required" at the beginning of blah.rb)
[17:49:23] d08z: tubbo: i know but then the lib is only useable in rails, not in "generic" ruby
[17:49:56] d08z: tubbo: the lib is being used in a ruby and a rails project
[17:50:39] d08z: tbuehlmann: yes and no, both symbols are loaded and works, the "blah" class is reloaded on each request but NOT the foo class (although loaded the first time)
[17:51:14] d08z: tubbo: the "require_dependency" instruction is in a rails controller, not in the libs
[17:51:57] d08z: then how do i "include and use my lib in /lib"
[17:52:26] d08z: its not a gem
[17:52:36] d08z: its a lib
[17:53:18] d08z: the ruby project uses "require /var/www/rails/.....lib/" lol
[17:53:44] d08z: but not here to discuss legacy code
[17:54:26] d08z: i ... *sigh* ....
[17:55:06] d08z: lets just rephrase my question: can i work on a lib under /lib without always re-starting the rails server
[17:55:30] d08z: in dev mode
[17:56:12] d08z: ok i think there might be a language barrier i dont know how to ask my question (which sounded so simple in my head)
[17:56:47] d08z: then how are the models and the controllers re-loaded on each requests?
[17:58:31] d08z: ok well thank you all for your time anyway
[17:59:44] d08z: should i put my /lib folder under /app as a "hack" lol
[18:00:59] d08z: event if i could make a gem
[18:01:20] d08z: yes but it does not reload
[18:01:27] d08z: so you cannot test rapidly
[18:01:49] d08z: you have to restart the server each time you modify the gem
[18:03:59] d08z: the problem with asking questions about programming is you always get answers about engineering :(
[18:04:51] d08z: tubbo: the questions has been hasked like 1,000,000 times on SO
[18:05:09] d08z: question asked
[18:06:54] d08z: in fact my question is really simple: how can i modify and reload the code of a file that is NOT under /app
[18:07:32] d08z: ... or so i thought
[18:08:55] d08z: tubbo: ok let's say i have a file called "foo.rb" that only contains ONE LINE: "require_relative bar.rb"
[18:09:20] d08z: and, in bar.rb there is only one line: "puts 'hello'"
[18:10:11] d08z: i move those two files in rails/my_app/lib
[18:10:37] d08z: in my controller i "require_dependency lib/foo.rb"
[18:11:09] d08z: i start the rails server, the console will print "hello"
[18:11:47] d08z: tubbo: are you still with me or am i not clear
[18:12:23] d08z: if add, in my sublime text, a line in foo.rb : "puts 'banana'"
[18:12:27] d08z: and hit refresh
[18:12:37] d08z: the console will now print banana
[18:12:46] d08z: so far so good right
[18:13:02] d08z: the problem is
[18:13:15] d08z: if i modify foo.rb
[18:13:37] d08z: i mean blah.rb
[18:14:00] d08z: and change 'hello' to 'hi' .. now the console STILL prints hello
[18:14:25] d08z: but the file has been required by the other file which was required_depdencily (!)
[18:14:53] d08z: yes this work
[18:16:03] d08z: i know i know but i thought that if i require_dependency a file, the whole "graph" is not loaded
[18:16:41] d08z: not = now
[18:17:32] d08z: yes i know i tested it
[18:17:47] d08z: i have like 10 solutions that are 80% good
[18:17:53] d08z: none are 100%
[18:18:13] d08z: --but then-- how does rails makes /app all magically works
[18:19:03] d08z: soooo, why does adding /lib to the autoload_paths considered a bad idea
[18:20:09] d08z: what happens if you put a file with a "require" instruction in /app
[18:20:46] d08z: mv lib/ app/lib
[18:21:58] d08z: look like asshole?
[18:22:51] d08z: lol im really confused with some things that i thought would be so simple
[18:22:59] d08z: programming i guess
[18:29:29] d08z: Quit: Lost terminal


[14:28:15] d08z: has joined #RubyOnRails
[14:34:26] d08z: Quit: leaving


[15:31:07] d08z: has joined #RubyOnRails
[15:31:19] d08z: does anyone know how to get rid of: Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
[15:31:36] d08z: (of course i did try gem pristine --all ....)
[15:32:07] d08z: i have read each SO post on the subject to no avail
[15:36:33] d08z: anyone? :)
[15:40:13] d08z: Quit: leaving


[14:10:01] d08z: has joined #RubyOnRails
[14:11:01] d08z: hi, does anyone know how to get rid of the spring warning message to run 'gem pristine --all'? (yes, i did run it and yes, i did go on stackoverflow before asking! :)
[14:13:18] d08z: yeah i read it
[14:13:46] d08z: suchness: didnt work
[14:14:48] d08z: suchness: ran the small script and typed 'gem pristine --all' and i still have the warning
[14:15:23] d08z: i ... dont understand what you mean
[14:17:58] d08z: nah i dont mind being "schooled", the only problem is i really dont understand what you mean
[14:18:36] d08z: i know but no gem is giving me problems
[14:19:35] d08z: thanks anyway for your time
[14:38:33] d08z: Quit: leaving
[19:09:30] d08z: has joined #RubyOnRails
[19:12:57] d08z: has left #RubyOnRails: ()


[17:10:19] d08z: has joined #RubyOnRails
[17:11:07] d08z: hi, i would like to know what is the accepted convention as where to put my custom executables/scripts in the ROR directory?
[17:11:39] d08z: elsurudo: there is no "/script"
[17:12:10] d08z: ok and then i just use "runner" ?
[17:12:41] d08z: tubbo: thats actually a very good idea
[17:13:49] d08z: tubbo: i thought only "provided-with-rails" binaries had to go in bin/
[17:16:33] d08z: tubbo: ok so, my own libs in libs/, my script in bin/ and the 3rd party lib i need for the script in vendor/, am i getting this right?
[17:31:03] d08z: Quit: leaving


[17:40:52] d08z: has joined #ruby
[17:51:55] d08z: Quit: leaving