#RubyOnRails - 10 April 2017
« Back 1 day Forward 1 day »
[00:59:37] das3in: Hi everyone, I'm writing a request spec for a rails api and when i run my test it's returning "missing template for this request format ["text/html"]" - how can i bypass this?
[04:11:24] JDeen: Hello there.. I got a question on nested attributes and Rails5. I have 3 models Account, Membership, User (some thing like this: http://stackoverflow.com/questions/13506735/rails-has-many-through-nested-form). But when I create an account with a user, I get an error on membership that 'memberships.account must exist'. Its regarding the new rails behaviour regarding belongs_to. How can I fix this?
[04:24:15] JDeen: sevenseacat: ya sure... i was witing for my machine too boot... here it goes... https://gist.github.com/ziyan-junaideen/d3d62221e9d24530aa304ca5fa99de17
[04:31:51] JDeen: Radar: good afternoon, I remember you are in Aus? its morning here in Sri Lanka... was the comment above for me?
[04:33:47] JDeen: cool, thats good to know, because then it can be fixed... what silly did i do there pls...
[04:58:35] sevenseacat: jdeen: can you try changing `belongs_to :account` to `belongs_to :account, inverse_of: :memberships` in the Membership model? out of curiosity
[05:59:05] dminuoso: Is there anyone who has tried to re-structure rails folders to organize by feature?
[05:59:41] dminuoso: sevenseacat: Why so? At least the controller/view/helpers are usually coupled extremely tightly.
[06:03:06] dminuoso: sevenseacat: I mean you do have a point. It makes magical things like "render @post.comments" require explicit partials -> but I actually kind of enjoy explicitly referring views because it conveys clear intend.
[12:05:53] sunya7a: Radar: good evening. did you have a chance to take a peek at that where query. what's your opinion on the safety of it?
[15:47:16] ketan: Hi everyone, can anyone recommend how to test a method that has `return unless Rails.env.production?`
[15:48:45] dminuoso: ketan: Though personally I would advise against any unless Rails.env.production? in the first place.
[15:49:02] dminuoso: Behavior that depends on which environment it runs on is error prone and will make your tests lose a lot of value.
[15:49:28] dminuoso: ketan: That test for that specific component has 0 value, because it won't say anything about production (which means its useless)
[15:49:59] ketan: What could I use instead, the method redirects to https and we don't want this behaviour in test or development
[15:51:09] ketan: this is a rails 2 project which doesn't have config.force_ssl, so I need to make our site https site wide
[15:51:29] dminuoso: ketan: I would say mimic the same behavior. Write your own middleware to do this.
[15:54:13] dminuoso: ketan: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/ssl.rb
[15:54:31] dminuoso: This is the current implementation. It's very likely that you can reuse this with little to no modification.
[16:27:58] liquid-silence: using devise with nested forms and its not creating the nested model, receiving a ActiveRecord::AssociationTypeMismatch: Company(#70111777399940) expected, got ActiveSupport::HashWithIndifferentAccess(#70111765387260) error
[17:03:31] Cache_Money: I have a custom validation that looks verifies that a column is unique. However, when I go to update the record it throws an error because that column value already exists.
[17:03:42] Cache_Money: How should I modify my validation? https://gist.github.com/anonymous/170aa9598352785f53fc4b79d6399fd1
[17:05:28] tbuehlmann: Cache_Money: any reason why you don't use rails' uniqueness validation for this?
[17:06:26] Cache_Money: tbuehlmann: I was just thinking about that myself. I'm not sure why I originally did that... I just changed my validation to use `uniqueness` and I'm able to update just fine. I'll move to that approach
[19:17:51] patarr: Why do I continuously get i18n-debug debug level log messages when I set the rails logger to :info?
[19:28:44] patarr: epochwolf: I've verified that something is resetting my level to 0 on Rails.logger
[19:28:59] patarr: I step through and debug my initializers, and the loggers they produce look good (set at 1 or Logger::INFO)
[19:29:13] patarr: But then I try bringing up a rails console, and check Rails.logger to see it has a 0.
[19:29:45] epochwolf: Well, you could modify the rails logger object and record every access to level?
[19:35:15] epochwolf: http://stackoverflow.com/questions/9786495/dynamically-replace-method-implementation-on-an-object-in-ruby
[19:54:27] patarr: I'm back with more questions :) I'm currently working with delayed_job, and I was wondering how I would set a breakpoint in some of its internal code with byebug. I write the line in there, and the BP _does_ get hit, but delayed_job seems to just continue chugging along ignoring my input (I can't step, etc)
[19:54:52] patarr: It's like some kind of background thread continued spewing things onto the screen, and my input was not registering with the BP
[20:04:39] Jon30: i am going crazy here.. why would a simple to_json with (include: [:id]) result in an error NoMethodError: undefined method `serializable_hash' for 154:Fixnum
[20:25:09] hazelux: Hey all! Has anyone played around with Docker + Rails? I'm having trouble with assets not resolving
[20:36:33] hazelux: dminuoso: did you bump into that issue too? How do you get around it? I tried accessing both the digested and non-digested asset and both 404'd
[20:53:06] dminuoso: hazelux: "Your car suddenly stopped working. Did you bump into that issue too? How did you get around it? I tried filling up the gas but it didn't work"
[20:54:04] dminuoso: hazelux: Instead of asking whether someone bumped into that issue, try figuring out the *cause* for that issue.
[20:55:00] dminuoso: Let's start by pointing out that docker has no impact on any Rails parts. So whatever problem you had, it was very likely unrelated to docker itself.
[20:57:01] hazelux: dminuoso: the problem is that the assets are 404'ing. I've tried accessing the fingerprinted asset and the bare asset, and none work. It only happens when inside of Docker
[21:02:22] dminuoso: hazelux: This is the time when you start showing me exactly what you are doing.
[21:05:58] hazelux: dminuoso: ok, I think I'm not doing anything fancy here. I have my application.js with different directives for sprockets, the front end is on React, so there's a separate file called react_bundle.js that sits in the public folder. The way I did it before Docker was to deploy and have rake assets:precompile run on every instance on AWS. Then I set `config.asset_host` to the CDN url, and that's it.
[21:06:25] helpa: If you're going to tell someone to "Just google it" or "RTFM", tell them what terms to use on Google exactly, or link them to the place in the documentation.
[21:07:02] helpa: hazelux: Clearly explain what is happening and create a Gist (http://gist.github.com), (formatted neatly please: http://bit.ly/1q75oia) of the code that is causing the problem you are encountering, as well as any useful output like stacktraces.
[21:07:53] hazelux: dminuoso: what do you need in the gist? Just wanna make sure I include everything.
[21:08:40] dminuoso: hazelux: Well as long as you create a personal gist (so you can add stuff as we go) let's just start with your config/application.js and config/environments/<your_env>.rb
[21:10:54] dminuoso: hazelux: Also just from personal experience, unless there are good reasons it's best if you completely separate rails from your react app.
[21:13:56] hazelux: dminuoso: here we go: https://gist.github.com/maxcodes/255ecfb9f6c2a7e95ae6e9130af08af5
[21:17:24] hazelux: just updated the gist with `assets.rake`. Assets live either in /public or in /app/assets, and then rake assets:precompile is run
[21:17:47] hazelux: That file just makes sure that the React stuff gets compiled as well when running rake assets:precompile
[21:21:38] dminuoso: hazelux: But I would look and check whether the glue between rails assets and the webpack manifest works properly.
[21:22:08] hazelux: dminuoso: no worries. It has nothing to do with the rest of the assets, it doesn't make much of a difference. It basically just runs webpack build.
[21:24:04] hazelux: dminuoso: the way I'm testing it is just accessing a single asset via its direct URL. All of them are failing (both CSS and JS). The asset helpers are fingerprinted. How can I know if the asset itself is fingerprinted?
[21:24:59] hazelux: dminuoso: oh, yeah. They are fingerprinted too. I have the non-fingerprinted version in `app/assets` and the fingerprinted in `public/assets`
[21:26:50] dminuoso: hazelux: Well look at the url from any assets helper then. Does the URL look valid? If so you deployed it wrongly.
[21:31:48] hazelux: dminuoso: it does, and it still 404s. Say I have an asset called `verified.png`. I have `verified-fingerprint.png` in `public/assets`. If I visit `localhost/assets/verified-fingerprint.png` I get a 404...why would this be?
[21:34:24] dminuoso: hazelux: http://edgeguides.rubyonrails.org/asset_pipeline.html#cdns consult section 4.4.2
[21:37:58] dminuoso: hazelux: Also wrt to your question, it's very simple. You dont have rails configured to serve assets...
[21:38:27] dminuoso: 23:31 < hazelux> dminuoso: it does, and it still 404s. Say I have an asset called `verified.png`. I have `verified-fingerprint.png` in `public/assets`. If I visit `localhost/assets/verified-fingerprint.png` I get a 404...why would this
[21:39:19] dminuoso: hazelux: https://gist.github.com/maxcodes/255ecfb9f6c2a7e95ae6e9130af08af5#file-production-rb-L23
[21:40:38] dminuoso: hazelux: And since you also configured it to not fallback to dynamically generating them when a static asset is missed: https://gist.github.com/maxcodes/255ecfb9f6c2a7e95ae6e9130af08af5#file-production-rb-L30
[21:41:21] dminuoso: So all in all you neither precompiling the assets in your Dockerfile, nor is Rails configured to serve them if they were precompiled.
[21:43:46] hazelux: dminuoso: oh wow. Yeah that sounds bad. Ok, I didn't know about this. Thanks for the pointers!
[21:48:14] dminuoso: hazelux: Also if you want a sleek and elegant and actually simple webpack integration, look at this: https://github.com/mipearson/webpack-rails
[21:53:22] hazelux: I tried both, and I ended up liking react_webpack_rails a little better. webpack-rails seems a bit more widely used though
[22:25:58] matthewd: carlosd: But really, if you're using gem A's goodies, you generally be listing it in your gemfile anyway
[22:26:57] dminuoso: hazelux: After about 2 days I raged too much and just created a new repo with just raw webpack.
[22:27:19] dminuoso: hazelux: My coworkers still hate me for the amount of pencils and other office items I have thrown around me.
[23:00:04] sunya7a: Radar: i see jquery.turbolinks in application.js .. so i don't understand why it doesn't like this one