#RubyOnRails - 18 July 2017
« Back 1 day Forward 1 day »
[00:05:50] xco: hi, how do i reload page content in tests on line 10? https://gist.github.com/siaw23/b9696b6204c3662a47e8f53bcc8e43ed
[00:14:24] xco: Radar: i’m testing a remember login path. if i make my test look like this https://gist.github.com/siaw23/b9696b6204c3662a47e8f53bcc8e43ed i feel there’s something wrong cause then im’ explicitely requesting the same page as before and not the app sending me to that page
[00:22:18] Radar: xco: I believe login_as just sets up the session. It doesn't make the requests to actually login as the user.
[00:22:44] Radar: Perhaps that's what you want to do? When you're redirected to new_session_path and then actually complete a proper login by filling in the fields then assert that the user is redirected to that path?
[00:58:41] emers2n: If I want to show a link to a random post sitewide in the footer, where do I put the controller code so it's available site wide?
[00:58:49] emers2n: Controller code I'm using for a random post: Post.offset(rand(Post.count)).first
[02:23:08] rubio: Hi here! i need some help... i like to use the asset:precompile but without creating a single bundle file (specially JS), the idea is that the engine return all the files as in develop mode, but they should be one by one, uglified and minified/gzipped
[03:59:27] bios: hey *.. I'm having a hard time with something simple.. I want to have a link the user can click to duplicate a record.. I've got a controller action that duplicates the record and redirects to the new record.. I'm having issues with the route and also with the link_to .. any tips on best way to do that
[09:31:03] Terens: Behind a reserse proxy nginx or when using passenger-nginx when serving sidekiq assets I get
[09:31:29] Terens: ActionController::UnknownFormat (DashboardController#index is missing a template for this request format and variant.
[10:16:28] krmela: hello there i have model WeekDay which has many dayoffer and Food which has many day offer i dont know how to make for given WeekDay in one array put related foods and in second array unrelated foods
[10:28:05] tbuehlmann_: krmela: so you want all associated dayoffers for one specific weekday and then all not associated dayoffers for that same weekday?
[10:30:51] tbuehlmann_: I don't understand the connection to Food yet. can you gist your models and their associations?
[10:36:29] tbuehlmann_: still not sure I understand. for a given week_day you want to get what exactly?
[10:37:27] krmela: tbuehlmann_: well it is web for big canteen so we have various foods choices stored in foods
[10:37:59] krmela: tbuehlmann_: days are stored in weekday and day offer is restricted set of choices for given day
[10:40:30] tbuehlmann_: https://gist.github.com/tbuehlmann/db14f7aab4d0cdc01a37f14686156612#file-week_day-rb-L3
[10:42:31] krmela: tbuehlmann_: and second part of question is how to get for give workday unassociated foods i am plan to display two groups of check boxes and and on save process two arrays
[10:43:44] tbuehlmann_: you could write a clever join condition, but I'm too lazy for that right now. this could work: Food.where.not(id: week_day.foods.select(:id))
[10:47:24] krmela: well guys dminuoso and tbuehlmann thanks for help btw if you coming nearby Olomouc in Czech Republic poke me i am glad invite you for some beer
[13:18:00] ule: Hey guys.. what do you think about forwarding to a model a hash instead of passing via parameters? For example: inside my "def create" I call MyModel.new(permitted_params) instead of MyModel.new(name = nil, email = nil, address = nil, phone = nil) and so on?
[13:18:25] ule: I was told that its a bad practice forwarding a hash to a model and this should be passed as parameters
[13:20:52] tbuehlmann_: that's basically how activemodel and activerecord objects work. are you sure the senior doesn't mean something else?
[13:21:41] ule: tbuehlmann_: I shouldn't forward to my model something that "Rails" deals on controllers
[13:21:47] vedu: ule: its hard to understand. You are saying that you want to do something like MyModel.new(name = nil, email = nil, address = nil, phone = nil) ?
[13:22:22] tbuehlmann_: are you really really sure? maybe the senior means to not throw the raw params into the method call rather than using strong params?
[13:23:02] ule: tbuehlmann_: I'm actually passing the hash affter calling a private method with .permit and all that idea
[13:24:03] ule: I found this video to support my argument.. https://www.youtube.com/watch?v=4e-_bbFjPRg
[13:24:03] tbuehlmann_: what if you _don't_ want to update a single one of the attributes? providing nil obviously doesn't work
[13:24:55] ule: yeah.. providing nil or not nil it's not the point.. the point mention was not passing params as hash to a model
[13:25:16] matthewd: ule: It's literally the Active Record API, used in every example controller/action everywhere.. I'm not sure what else we can offer
[13:26:12] ule: yeah thank you guys.. I'm gonna refactory my code here.. I got to a point where I'm passing 4 parameters which is becoming ridiculous
[13:32:15] ule: for example.. if inside my "def index" I have something like MyModel.new.users_custom_method(permitted_params) ?
[13:34:01] matthewd: Well it's ultimately a design decision, which is theoretically what a senior developer is there for
[13:38:20] shilon: hello there, I’m starting to use money and currencies. To switch between currencies do I need to make add the rate myself or can I use a gem for that? How can I have a select_field with only currencies I want? Can I define the currencies available?
[14:23:29] rubio: Hi here! i need some help... i like to use the asset:precompile but without creating a single bundle file (specially JS), the idea is that the engine return all the files as in develop mode, but they should be one by one, uglified and minified/gzipped
[14:26:06] fryguy: in config/application.rb, config.assets.precompile can take a Proc for what to precompile instead of a static list
[14:27:27] rubio: fryguy: the reason behind is to take advantage of http/2 protocol for parallel downloads... :D
[14:28:55] fryguy: because http will parallel download, sure, but that won't be any faster than downloading a single file.
[14:31:38] rubio: the theory say that parallels should be faster... but i will let you know the results, maybe this can we added later as a "inline comment" on the default code... :D
[14:36:45] fryguy: rubio: you'll lose compression efficiency from compressing multiple smaller files instead of 1 larger file
[14:38:57] rubio: let me test and i will let you know.... normally the bottleneck is the internet latency and slowness on a single thread... but lets make some tests :D
[16:25:55] mwlang: I’m just curious (seeking ideas): How would you refactor this? https://gist.github.com/mwlang/09958e44a202654783e4b24348e9d754
[16:27:18] mwlang: basically, the code’s stopping a delete of a party record if it’s referenced in a number of different scenarios (read: tables)
[16:53:04] greengriminal: Can someone shed a bit of light on an issue I'm facing. My problem is rails is failing to load an asset in the test env.
[16:53:20] greengriminal: I can confirm that in development the asset will load. This is the gist I have prepared: https://gist.github.com/davidpatters0n/9c5f5d00917a88f01916afbfc0a7c6c7
[16:55:12] mwlang: not sure if that’s your issue or not, but frequently when test or development start behaving differently from each other, spring is the culprit for me.
[16:57:59] greengriminal: mwlang, - Should i be running `spring stop` from within the rails test console ?
[16:59:54] greengriminal: Appears to not make a difference. If i re-run `Rails.application.assets.find_asset('foundation_emails').to_s` in a rails test console.
[17:00:52] leggomygreggo: Hi. So im getting a kinda weird error. I display a group of categories. They are in a certain order but when I update the a field for a certain category, the category moves to the bottom of the page. This happens with all the categories and cycles like that each time i update one. I am assuming there is some kind of ordering default that puts the most recently updated one on the bottom
[17:03:51] leggomygreggo: <% Category.where(report_id: @report.id).order(name: :desc).each do |category| %>
[18:22:37] boreddanman: Basically I have a model which represents a single access of a file. Most relevant attributes are: ID, filename, date_accessed, and ip_address. I want to group on filename and pluck the top 10 records ordered by the count of distinct ip_addresses, but also retrieve the total count. How can i get both aggregations in one query?
[18:27:58] yebyen: Greetings, I am wondering if anyone knows how to manipulate sessions in ActionController::Integration::Session
[18:28:47] yebyen: I found out that I can do "rails console" and run "app.get '/'" and get back a request response and use this way to do debugging
[18:29:21] yebyen: but my login process goes out to CAS for auth and I'm not sure how the authorization is handled, because it's done by rack-cas
[18:29:39] yebyen: I just need to make sure that session["cas"]["user_id"] is set before the request is handled
[18:30:34] havenwood: yebyen: https://apidock.com/rails/ActionController/IntegrationTest/open_session
[18:31:42] havenwood: yebyen: Third time's the charm: http://api.rubyonrails.org/v5.1.0/classes/ActionDispatch/Integration/Runner.html#method-i-open_session
[18:33:27] yebyen: this looks like I could set up a session and manipulate it through posts, if I have a post endpoint for what I'm trying to do
[18:33:47] havenwood: it's mixed in afaik, you can just: open_session do; assert_equal session['yebyen'], 'yebyen'
[18:37:36] yebyen: and send a simple post with a username and password to whatever FakeCAS endpoint is listening, like rack-cas does in ENV=test
[18:38:07] yebyen: that might be the best thing to do, because honestly I don't think I need to manipulate the session directly for anything other than to get past my authenticate before
[19:23:02] yebyen: havenwood: i wound up just dropping a pry statement in before the point that checks if session['cas']['user'] is set
[19:23:34] yebyen: now I can app.get '/' and follow redirects to my heart's content, session persists without any open_session tricks
[19:23:49] yebyen: i have no idea why just sending a post to /login doesn't work with rack-cas fakecas
[19:24:30] yebyen: not sure what's supposed to happen after that, but in my browser I wind up logged in
[19:25:27] yebyen: maybe there's something that isn't set in the rack-cas fakecas middleware when you do it this way
[20:11:19] yebyen: rack-cas seems to be sending me a redirect with no destination, but in my browser it definitely goes
[20:23:49] benlieb: I'm having a problem using my_relation.any? when my_relation uses a select() clause with an "AS" in it. https://gist.github.com/benlieb/20fb447140cf303b72d1d7bce724cfd8
[20:24:16] benlieb: a col that I'm using in the group no longer exists: ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "num" does not exist LINE 1: ...", "sale_commissions"."commission_rate" ORDER BY num desc, ...
[20:27:51] bennyzr: Hi, anybody have any suggestions on implementing a user id stamp with active record?
[21:49:18] rubycoder37: I'm trying to write tests with the default stack (minitest, fixtures, etc), but I have devise installed, do I need to create a user fixture first and then use one of the devise helpers to authenticate?
[21:58:00] fryguy: rubycoder37: you might find this helpful: https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-(and-RSpec)
[23:46:45] |PiP|: How can I get the internal values of an ActiveRecord object, right before save? I don't want to call the public/external methods, but rather, I'd like to retrieve the true internal representation of the data that will be persisted to the database.
[23:47:13] |PiP|: Basically, I want the values that will be sent to the database when a .save() is called
[23:47:56] |PiP|: Is there an internal hash or something, where that data lives, inside each AR object?
[23:52:52] |PiP|: Ahh, found it. Is it the "attributes" method that returns the internal representation?