« Back to channel list

#RubyOnRails - 11 July 2019

« Back 1 day Forward 1 day »
[00:07:34] orbyt_: has joined #RubyOnRails
[00:10:32] skryking: has joined #RubyOnRails
[00:28:42] Guest42592: has joined #RubyOnRails
[00:43:05] orbyt_: has joined #RubyOnRails
[00:49:20] emachnic: has joined #RubyOnRails
[01:27:44] emachnic: has joined #RubyOnRails
[01:34:48] caduguedess: has joined #RubyOnRails
[01:47:14] Saukk: has joined #RubyOnRails
[01:48:03] deepredsky: has joined #RubyOnRails
[01:48:03] jstrong: has joined #RubyOnRails
[01:49:56] srinidhi: has joined #RubyOnRails
[01:57:08] nav2002: has joined #RubyOnRails
[01:59:00] jstrong: has joined #RubyOnRails
[02:06:31] RiPuk: has joined #RubyOnRails
[02:07:58] ariedler: has joined #RubyOnRails
[02:10:49] aert: has joined #RubyOnRails
[02:12:43] SteenJobs: has joined #RubyOnRails
[02:38:22] alnk: has joined #RubyOnRails
[02:38:57] RiPuk: has joined #RubyOnRails
[02:39:26] jstrong: has joined #RubyOnRails
[02:39:56] alnk: has joined #RubyOnRails
[02:53:55] TvL2386: has joined #RubyOnRails
[02:55:09] DTZUZO: has joined #RubyOnRails
[03:05:35] emachnic: has joined #RubyOnRails
[03:13:06] brendan-: has joined #RubyOnRails
[03:17:14] jstrong: has joined #RubyOnRails
[03:24:38] gambl0re: has joined #RubyOnRails
[03:33:42] jstrong: has joined #RubyOnRails
[03:37:47] jstrong: has joined #RubyOnRails
[03:40:57] Joufflu: has joined #RubyOnRails
[04:08:56] ariedler: has joined #RubyOnRails
[04:19:52] brendan-: has joined #RubyOnRails
[04:52:57] srinidhi: has joined #RubyOnRails
[05:19:12] conta: has joined #RubyOnRails
[05:40:23] emachnic: has joined #RubyOnRails
[05:54:48] schne1der: has joined #RubyOnRails
[06:00:40] conta: has joined #RubyOnRails
[06:06:57] xco: has joined #RubyOnRails
[06:16:58] RiPuk: has joined #RubyOnRails
[06:40:13] haxx0r: has joined #RubyOnRails
[06:41:50] ascarter: has joined #RubyOnRails
[06:45:00] haxx0r: def active_for_authentication?
[06:45:03] haxx0r: in my User model
[06:45:10] haxx0r: but when i login via devise, it never hits
[06:45:13] haxx0r: did they remove that?
[06:55:09] sandstrom: has joined #RubyOnRails
[06:56:47] schne1der: has joined #RubyOnRails
[06:57:44] lxsameer: has joined #RubyOnRails
[06:58:28] xco: is a scope like this a thing in Rails? `-> { where.has { user_id.not_eq(nil) } }`
[06:58:35] xco: ‘where.has’?
[07:04:20] emachnic: has joined #RubyOnRails
[07:14:54] xco: got it. it’s from here https://github.com/rzane/baby_squeel
[07:25:24] conta: has joined #RubyOnRails
[07:27:40] SteenJobs: has joined #RubyOnRails
[07:40:07] SteenJobs: has joined #RubyOnRails
[08:08:32] conta: has joined #RubyOnRails
[08:10:35] ariedler: has joined #RubyOnRails
[08:13:51] ascarter: has joined #RubyOnRails
[08:18:25] m17: NL3limin4t0r, looks like I am able to access it. User is locked though
[08:24:30] ascarter: has joined #RubyOnRails
[08:28:13] emachnic: has joined #RubyOnRails
[08:49:59] deepredsky: has joined #RubyOnRails
[09:17:20] snowy: has joined #RubyOnRails
[09:18:43] conta: has joined #RubyOnRails
[09:23:45] NL3limin4t0r: Norrin: This still needs to mentioned in the documentation, but the hash passed to `foreign_key: {}` is forwarded to `add_foreign_key`. Options can be found there.
[09:24:01] NL3limin4t0r: https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_foreign_key
[09:24:10] Dbugger: has joined #RubyOnRails
[09:24:37] NL3limin4t0r: The only reason the :to_table is mentioned seperately is because it's normaly not an option, but the second argument.
[09:37:49] sandstrom: has joined #RubyOnRails
[09:38:25] ZAJDAN: I need add into my app new input which should save values into own column in DB....do I have to add this column into model and then migrate?
[09:41:06] ZAJDAN: or only via command 'rails generate migration add_newinput_to_mytable newinput:string
[09:46:17] dtzuzu: has joined #RubyOnRails
[09:50:15] NL3limin4t0r: ZAJDAN: Adding it to the database through an migration should be enough. Rails will pick it up on restart.
[09:50:38] ZAJDAN: ok...thnx
[09:52:54] NL3limin4t0r: You might need to add validations though. For example, if you decided that the column has `null: false` you should also add the validation `validates :newinput, precense: true`
[09:54:16] ZAJDAN: after the generate migration is neccessary launch command 'rake db:migrate' ?
[09:55:20] NL3limin4t0r: When the migration is to your liking yes. It only being in the migrations isn't enouth. Rails picks up columns in the database, if it's not there Rails will not reconize it.
[09:57:22] ZAJDAN: name of the column can not be via capital letters?
[09:58:20] ZAJDAN: rails generate migration add_EB_to_commissions EB::integer
[10:01:00] dtzuzu: has joined #RubyOnRails
[10:15:41] conta: has joined #RubyOnRails
[10:21:57] ZAJDAN: 'rails db:schema:load' empty the database?
[10:28:37] TurtleTony: has joined #RubyOnRails
[10:31:01] TurtleTony: has joined #RubyOnRails
[10:33:26] ZAJDAN: has joined #RubyOnRails
[10:36:48] ZAJDAN: how to solve migrations problem? NameError: uninitialized constant AddEbToCommissions
[10:39:32] dtzuzu: has joined #RubyOnRails
[10:55:07] ariedler: has joined #RubyOnRails
[11:02:11] lankanmon: has joined #RubyOnRails
[11:03:42] xco: hi anyone knows why i’m getting this in development mode? https://gyazo.com/778e2803211d35fc8f4840642661da69 and how do i show the real rails errors (in red) instead?
[11:11:14] dionysus69: xco you are running in production, you need to config.consider_all_requests_local to true in production.rb, but of course you should not do that if your server is really in production
[11:12:53] xco: dionysus69: thanks. that’s done but still not working
[11:14:04] DTZUZO: has joined #RubyOnRails
[11:17:03] emachnic: has joined #RubyOnRails
[11:18:09] RiPuk: has joined #RubyOnRails
[11:18:14] xco: is there a better way to write this? `params[:something] = [] if params[:something].blank?`
[11:20:35] dionysus69: yea that's not ruby pretty, but I fear even jedies have to write like that
[11:22:06] xco: doesn’t look too good to me, there’s something about it that i can figure out
[11:34:52] NL3limin4t0r: xco: You could do `params[:something] ||= []`, with the difference that if params[:something] is an empty or whitespace string the value is not set to an array.
[11:36:08] xco: that would mean if params[:something].blank? it should set it to []
[11:36:23] xco: because #blank? checks for nil too i think
[11:36:26] xco: NL3limin4t0r: right?
[11:36:33] dionysus69: nil and empty obj both
[11:36:56] xco: dionysus69: yeap
[11:37:12] NL3limin4t0r: and in the case of strings " \n " is also considdered blank.
[11:37:50] NL3limin4t0r: `params[:something] = []` only sets params[:something] of the current value is falsy which might be enouth.
[11:38:24] NL3limin4t0r: s/of the/if the/
[11:39:14] xco: this doesn’t look right `params[:something] = []`
[11:39:36] xco: aren’t you explicitely overwriting params[:something]?
[11:39:43] NL3limin4t0r: oops, that should be `params[:something] ||= []`
[11:41:17] NL3limin4t0r: If the value of params[:something] isn't a string the `||=` will do fine.
[11:41:31] NL3limin4t0r: Otherwise you might first want to clear empty value.
[11:42:02] NL3limin4t0r: `params.reject! { |_key, value| value.blank? }`
[11:42:40] NL3limin4t0r: ^ removes all key/value pairs with a blank value
[12:01:17] RiPuk: has joined #RubyOnRails
[12:17:15] RiPuk: has joined #RubyOnRails
[12:27:11] conta: has joined #RubyOnRails
[12:35:37] RiPuk: has joined #RubyOnRails
[12:43:14] srinidhi: has joined #RubyOnRails
[12:53:05] ZAJDAN: I have form where is field which is not required....in a case when user will not fill it I would like to save into db some predefined value....the best is set it in Model ?
[13:04:50] srinidhi: has joined #RubyOnRails
[13:07:50] za1b1tsu: has joined #RubyOnRails
[13:15:25] NL3limin4t0r: ZAJDAN: If you define a database column default Rails will handle it for you.
[13:16:30] ZAJDAN: aha aha...Thnak You
[13:19:05] NL3limin4t0r: for example: t.string :status, null: false, default: 'new'
[13:20:25] NL3limin4t0r: or if you need to change an existing column: change_column_default :opportunities, :status, from: nil, to: 'new'
[13:23:38] NL3limin4t0r: You could run into trouble when passing an empty string. In which case you might need to alter the attribute setter of your model.
[13:24:20] NL3limin4t0r: HTML forms always submit their value. If not filled an empty string is submitted.
[13:25:40] NL3limin4t0r: Use: `def your_attribute=(value); super(value.presence); end` to convert those empty strings into `nil` values.
[13:25:52] NL3limin4t0r: ^ In your model ofcouse
[13:50:46] jstrong: has joined #RubyOnRails
[14:00:24] tf2ftw: has joined #RubyOnRails
[14:04:52] uksio: has joined #RubyOnRails
[14:08:20] Saukk: has joined #RubyOnRails
[14:14:46] jstrong: has joined #RubyOnRails
[14:21:47] schne1der: has joined #RubyOnRails
[14:38:57] Dr_MDMA_MD: has joined #RubyOnRails
[14:46:01] brianpWins: has joined #RubyOnRails
[14:47:49] brianpWins: I don't think this is actually a rails problem theres likely something else at play but I figured I'd ask: Anyone ever have a single model in your up claim that it's comitting changes to the db but that table is just empty. Every other model/table works fine. But this one model keeps saying it's saving or creating records and yet the table is entirely empty. I can use rails dbconsole and manually insert re
[14:47:50] brianpWins: cords without a problem. Using the same sql that AR is outputting in the logs when it claims it's doing the same thing.
[14:56:06] jstrong: has joined #RubyOnRails
[14:57:03] Tempesta: has joined #RubyOnRails
[15:01:15] jstrong: has joined #RubyOnRails
[15:02:04] tf2ftw: has joined #RubyOnRails
[15:08:01] ElFerna: has joined #RubyOnRails
[15:31:40] gambl0re: has joined #RubyOnRails
[15:42:01] Exuma: has joined #RubyOnRails
[15:55:59] SteenJobs: has joined #RubyOnRails
[15:59:51] orbyt_: has joined #RubyOnRails
[16:03:19] timdotrb: has joined #RubyOnRails
[16:03:43] Exuma: has joined #RubyOnRails
[16:03:45] tf2ftw: has joined #RubyOnRails
[16:11:46] Saukk: has joined #RubyOnRails
[16:12:20] psilly0: has joined #RubyOnRails
[16:13:16] SteenJobs: has joined #RubyOnRails
[16:17:21] Exuma: has joined #RubyOnRails
[16:23:35] tf2ftw: has joined #RubyOnRails
[16:26:30] Jon30: has joined #RubyOnRails
[16:27:32] Jon30: hey guys, I setup cron with whenever gem, and when it executes a custom rake command, i end up with: "NameError: uninitialized constant Devise"
[16:30:44] Jon30: it occurs on initializers/devise.rb:5:in which is "Devise.setup do |config|"
[16:31:10] Inside: can you paste the rake test?
[16:31:38] Inside: you probably need to be doing task task_name: :environment do {...}
[16:31:52] tdy4: has joined #RubyOnRails
[16:38:37] Jon30: task test_task: :environment do
[16:38:46] Jon30: which is wrapped in namespace :test_namespace do
[16:40:38] NL3limin4t0r: Jon30: It might be easier understandable in a code snippet. "Paste 4+ lines of text to https://dpaste.de/ and select ruby as the language" - #RubyOnRails title
[16:50:22] tf2ftw: has joined #RubyOnRails
[16:50:59] Jon30: https://gist.github.com/slavajacobson/fd22c3ee46c2a4f782336f082d67b16c
[16:51:04] Jon30: hopefully this is more helpful :)
[16:55:54] havenwood: Jon30: Did you?: bundle install
[16:56:38] havenwood: Jon30: Is Devise in your Gemfile.lock?
[16:56:44] Jon30: havenwood: yes. the app works just fine. I am able to use Devise to create an account, login, protect pages with authenticate_user
[16:57:07] tf2ftw: has joined #RubyOnRails
[16:57:15] havenwood: Jon30: What's the command you run to get that error?
[16:57:27] Jon30: havenwood: yes devise is in Gemfile.lock
[16:57:47] Jon30: havenwood it's run by cron
[16:58:09] havenwood: Jon30: I'm assuming cron isn't running in the context of your bundle. What's the command cron is running?
[16:58:37] Jon30: it works just fine if i try to manually execute - rake test_namespace:test_task
[16:59:17] havenwood: Jon30: What's the crontab executing? What command? It seems it's not in the context of your bundle, which you'd get by prefixing `bundle exec` or `bin/rake` from app root.
[16:59:25] Jon30: havenwood it's in the gist URL. I will try to copy it as one line to IRC: "every 1.month do rake 'test_namespace:test_task' end
[17:00:04] Jon30: then when it executes, i get an error in my cron.ERROR.log saying NameError: uninitialized constant Devise
[17:00:08] havenwood: Jon30: Ah, yeah - that should be `bin/rake` or `bundle exec rake`. How'd you install Ruby?
[17:00:30] havenwood: Prefix `bundle exec` or it's not using your bundle!
[17:01:11] havenwood: https://i.imgur.com/2Hlpoov.png
[17:01:39] Jon30: havenwood: prefix that within schedule.rb? so basically - every 1.month do bin/rake 'test_namespace:test_task' end
[17:02:14] Jon30: when you run rake within schedule.rb, doesnt' it already use the bundle?
[17:03:09] Jon30: I have another project where i am using whenever gem and within schedule.rb i am simply adding "rake 'namespace:action'" and it works just fine, but that project doesn't have Devise, so i am not sure why it isn't working this time
[17:03:28] Guest42592: has joined #RubyOnRails
[17:03:47] Guest42592: has joined #RubyOnRails
[17:12:24] NL3limin4t0r: Jon30: What value have you set for `job_type :rake, 'what value is here?'`
[17:12:48] NL3limin4t0r: And can you compare that with your other project?
[17:13:38] havenwood: Jon30: No, just running `rake` doesn't use your Bundle unless you're using RVM and are in the app directory.
[17:13:52] Jon30: NL3limin4t0r: it's not set to anything on both projects
[17:14:02] havenwood: Jon30: In modern Rails, you can use the `bin/rails` command for rake tasks.
[17:14:33] NL3limin4t0r: We also use the whenever gem and it's set to `job_type :rake, 'cd :path && RAILS_ENV=:environment bundle exec rake :task :output'`
[17:15:47] tf2ftw: has joined #RubyOnRails
[17:16:00] Jon30: havenwood: i am using RVM and I believe the whenever gem knows how to find the bundle? it first changes the directory into the project directory and then it calls: RAILS_ENV=production bundle exec rake test_namespace:test_task --silent
[17:16:14] havenwood: Jon30: https://rvm.io/deployment/cron
[17:16:20] Jon30: thanks i will take a look
[17:16:21] Saukk: has joined #RubyOnRails
[17:16:35] havenwood: Jon30: With RVM and cron, you might want to use wrappers. Wrappers are RVM's way of dealing with this scenario.
[17:17:08] conta: has joined #RubyOnRails
[17:17:11] havenwood: Jon30: RVM automagically prefixes `bundle exec` for you, but it doesn't work with cron.
[17:18:31] Jon30: havenwood: it did though. Here what it generated: 0 13 1 * * /bin/bash -l -c 'cd /home/xxx/public_html/xxx/website/releases/20190606161334 && RAILS_ENV=production bundle exec rake xxx:xxx --silent >> /home/xxx/public_html/xxx/website/shared/log/cron_log.log 2>> /home/xxx/public_html/xxx/website/shared/log/cron_log.ERROR.log'
[17:18:37] Jon30: i replaced sensitive information with xxx
[17:18:43] Jon30: so what am i missing?
[17:18:47] NL3limin4t0r: Yep, I just noticed in the whenever documentation that the default for :rake is "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output" https://github.com/javan/whenever#define-your-own-job-types
[17:20:10] conta: has joined #RubyOnRails
[17:28:25] NL3limin4t0r: What happens when you add `require 'devise'` to your initializer? It doesn't hurt, since it only requires if not already loaded.
[17:30:09] NL3limin4t0r: If that doesn't help I have not mutch of an idea. It's getting late so I wish you good luck.
[17:30:19] Jon30: thanks. I was considering to do that but wasn't sure if it's the right practice. I'll try it
[17:30:27] Jon30: Thanks guys
[17:37:28] gambl0re: has joined #RubyOnRails
[17:38:01] srinidhi: has joined #RubyOnRails
[17:38:24] gambl0re: has joined #RubyOnRails
[17:53:19] Exuma: has joined #RubyOnRails
[18:46:16] skryking: has joined #RubyOnRails
[18:46:20] xco: has joined #RubyOnRails
[18:46:45] gambl0re: has joined #RubyOnRails
[18:47:12] caduguedess: has joined #RubyOnRails
[18:47:16] caduguedess: Hi, I've installed a Ruby on Rails project (OpenStreetMapWebsite https://github.com/openstreetmap/openstreetmap-website ). I can access it through localhost:3000 but I'm not receiving the confirmation email after signing up. I can only activate accounts through the Rails Console. I tried to follow RoR tutorials but couldn't figure it out. How could I set the mailer to make it work? I appreciate any help .
[18:48:34] caduguedess: in the folder /app/mailers/ there are the files notifier.rb and application_mailer.rb
[19:16:29] srinidhi: has joined #RubyOnRails
[19:30:20] s00pcan: has joined #RubyOnRails
[19:40:24] tf2ftw: has joined #RubyOnRails
[19:52:50] MasterAsia: has joined #RubyOnRails
[20:14:32] emachnic: has joined #RubyOnRails
[20:20:49] uks: has joined #RubyOnRails
[20:27:45] uksio: has joined #RubyOnRails
[20:40:20] szorfein_x: has joined #RubyOnRails
[20:41:17] pro777: caduguedess> Sorry for the late replay. Give this a try: https://github.com/ryanb/letter_opener
[20:42:18] caduguedess: Pro777 thanks, I will do it
[20:42:35] pro777: It just let's you look at and debug emails in your browser.
[20:45:45] SteenJobs_: has joined #RubyOnRails
[20:50:34] emachnic: has joined #RubyOnRails
[20:53:30] gb_away: has joined #RubyOnRails
[21:03:44] ur5us: has joined #RubyOnRails
[21:05:58] RiPuk: has joined #RubyOnRails
[21:06:39] mlt-: How do I interleave normal AR call with raw SQL in a single connection and single transaction?
[21:07:14] havenwood: mlt-: Can you not wrap them both in a transaction?
[21:07:29] mlt-: Do I just ActiveRecordBase.transaction do ... conn = ActiveRecord::Base.connection; ... ?
[21:07:55] mlt-: What confuses me is that #transaction
[21:08:05] mlt-: it is not called on a connection
[21:08:09] havenwood: mlt-: Have you already read?: https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
[21:08:42] havenwood: mlt-: "A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. "
[21:09:56] mlt-: So as long as I have a single connection from config/database.yml , all is good and I do not have to deal with connection_pool and furthermore I can store ActiveRecord::Base.connection in a variable?
[21:11:05] mlt-: It is just somewhat not clear that AR does not pool connections for a single DB configuration
[21:11:31] lxsameer: has joined #RubyOnRails
[21:20:41] Dr_MDMA_MD: has joined #RubyOnRails
[21:36:18] SteenJobs: has joined #RubyOnRails
[21:40:43] jstrong: has joined #RubyOnRails
[21:45:13] timdotrb: has joined #RubyOnRails
[21:50:22] RiPuk: has joined #RubyOnRails
[21:57:31] xco: has joined #RubyOnRails
[22:03:51] s00pcan: has joined #RubyOnRails
[22:06:21] jstrong: has joined #RubyOnRails
[22:08:11] mlt-: ACTION seems to have sorted things out
[22:18:50] LiamW: has joined #RubyOnRails
[22:19:39] LiamW: I have a form_for [@user, @award] which I would like to have post create at profile_badge_awards_path and put update at profile_badge_award_path
[22:20:02] LiamW: however, rails wants to submit it to users_badge_awards_path and users_badge_award_path
[22:20:04] LiamW: how do I change this?
[22:23:39] mlt-: I think you can have form_for(..., url: :users_badge_awards_path) IIRC
[22:25:23] mlt-: or other way around...
[22:25:36] mlt-: form_for(..., url: profile_badge_award_path)
[22:26:18] LiamW: it doesn't work for both post create and put update
[22:26:26] LiamW: it only works for one at at time
[22:26:37] LiamW: and I was hoping there was a nicer way than to add a ternary in the conditions
[22:26:58] s00pcan: has joined #RubyOnRails
[22:27:57] mlt-: I'm confused... how do you submit things other than one at a time?
[22:28:27] LiamW: the point of using form_for is that you can stick it in the _form partial for your resource and then use it from both the new and edit actions
[22:28:31] LiamW: this does NOT work if you want to do that
[22:28:49] mlt-: even if you specify url: ?
[22:28:54] LiamW: it works for ONE of them
[22:29:18] LiamW: it'll work for the new action if you specify url: :profile_badge_awards
[22:29:29] LiamW: it'll work for the edit action if you specify url: :profile_badge_award
[22:29:46] LiamW: it does not work for both at the same time
[22:29:51] LiamW: which is why I asked
[22:30:42] mlt-: you can't use singular symbol
[22:31:18] mlt-: instead of url: :profile_badge_award , it should be be url: profile_badge_award(@an_award)
[22:31:31] LiamW: that won't work either
[22:31:47] LiamW: profile_badge_award_path(@user, @award) will not work if @award is a new record
[22:31:57] LiamW: because it doesn't have the id information to key the route
[22:32:05] jstrong: has joined #RubyOnRails
[22:32:26] mlt-: oic... indeed you need a conditional
[22:33:59] mlt-: can't you do something like form_for(@user.profile, @award) ?
[22:34:12] LiamW: @user.profile isn't a relation
[22:34:23] mlt-: make it a table-less model
[22:35:43] LiamW: that won't key the route correctly either unless I do something like link it to a User and override to_param
[22:41:58] mlt-: Why? I think if you include ActiveModel::Model, it should do that for you
[22:42:34] mlt-: one of the google finds https://revs.runtime-revolution.com/creating-form-objects-with-activemodel-346e6c2abbf3
[22:42:54] Exuma: has joined #RubyOnRails
[22:48:08] LiamW: I'm just going to use the ternary for now
[22:54:22] jstrong: has joined #RubyOnRails
[23:05:18] orbyt_: has joined #RubyOnRails
[23:48:12] Dr_MDMA_MD: has joined #RubyOnRails