Activity Graph

Page 1 of 1


[12:06:54] maodun: has joined #RubyOnRails
[12:09:00] maodun: With Rails 5.1.2 and webpack, should new files in app/javascript/packs/ be automatically detected when I'm running webpack-dev-server and the default options. This is a new, from-scratch app.
[12:09:33] maodun: The code automatically picks up changes to existing packs fine, it just won't recognize a new pack unless I kill the server and restart it
[14:11:14] maodun: Quit: Leaving.


[10:29:43] maodun: has joined #RubyOnRails
[10:30:05] maodun: how can i easily validate that a number field != 0?
[10:33:46] maodun: sevenseacat: thanks, I looked at that, didn't see anything really clean, i'm guessing two lines:
[10:33:53] maodun: validates_numericality_of :my_field
[10:34:05] maodun: validates :myfield, exclusion: { in: [0] }
[10:41:05] maodun: Quit: Leaving.


[05:07:53] maodun: has joined #RubyOnRails
[05:08:50] maodun: I have a bunch of models I want to update together, where I either update all or none, but an update_all won't cut it because the updates to each model are different. What's the right way to tackle this?
[05:14:18] maodun: thanks ElSif
[05:19:57] maodun: Quit: Leaving.


[13:38:14] maodun: has joined #RubyOnRails
[15:27:03] maodun: Quit: Leaving.


[07:49:38] maodun: I'm trying to extract only the query string parameters of a request that has both a POST body and query string parameters. How can I do this?


[12:25:11] maodun: i'm trying to debug some xml that i'm rendering with a builder - is there a good way for me to log the rendered builder file?


[14:00:38] maodun: to_json is always escaping & to a unicode escape sequence. I have to communicate with a server that won't accept that and needs the raw ampersand. aside from doing a regexp search and replace, is there a way to tell to_json not to do that?
[14:00:50] maodun: some googling suggests JSON.stringify, but that seems to be gone in rails 4


[14:34:24] maodun: I have a url structure like /cities/mycity/foo/bar/baz?various-params-here, I want to be able to handle urls where mycity is "current" and redirect the browser to the correct geolocated city. But I want to leave the rest of the url structure intact. How can I do a redirect while just changing the mycity part?


[10:15:29] maodun: I need to generate json where the unicode is escaped to look like: \uabcd. How can I do this?
[10:15:34] maodun: in rails 4
[10:15:57] maodun: I believe the handling may be different than it used to be in previous versions of ruby


[11:01:49] maodun: what good reasons are there to process a job in the background when I'm already using a threaded server (like puma)?
[11:03:32] maodun: mikecmpbll, ok, but if the long thing was an ajax request that he's gonna want the result for anyway?
[11:04:10] maodun: i'm looking at doing some intensive ffmpeg processing, i just wonder if there's anything particularly bad in doing it in a thread on the server
[11:14:04] maodun: mikecmpbll, ok, thanks
[11:24:42] maodun: workmad3, mikecmpbll: thank you for the feedback, i will take all this into consideration


[07:39:46] maodun: I have the id for a session, which I retrieved via request.session_options[:id]. I want to retrieve the actual session data tied to that ID from the rails console. I'm using dallistore as my session cache. How can I accomplish this?
[07:40:32] maodun: I tried Rails.cache.fetch, but passing the value I got from request.session_options[:id] as the key returns nil
[07:41:44] maodun: rushed, I'm trying to access this from the console, not a rails controller
[07:43:53] maodun: I'm using a gem called impressionist to track users and it keeps track of a session of impressions based on a session key, which is request.session_options[:id]. At the end of the day I'd like to be able to do some more analysis about a user's session using this id
[07:44:46] maodun: rushed: thanks, looking into it


[09:07:53] maodun: I'm using dalli for session storage - how can I use it to calculate the number of unique visitors today?


[06:30:54] maodun: I have an instance of a model (City.find_by_name 'New York') that I want to load on rails start up and keep around for easy access for the duration of my application, how can I do this?
[06:31:30] maodun: The city to be loaded will be determined by environmental variables on start up


[07:46:17] maodun: How does yield work in a controller? When would a controller method be passed a block?
[07:46:23] maodun: Here's an example:


[07:49:16] maodun: I want to override parts of the devise confirmable model: I'm trying to rip out email confirmation and replace it with SMS confirmation. To do something like this, should I create a file in config/initializers and redefine the relevant functions there?
[07:49:42] maodun: Also, I want to be able to override some of the "included do??? end" code
[07:50:06] maodun: Should I just be forking the model? That seems like a lot of work for some moderate changes


[10:02:43] maodun: foo = users(:foo), when I use fixtures like this, my validations for my User model are run, can I avoid this?
[10:03:21] maodun: like a "build" equivalent instead of "create", which is what it seems to be doing?
[10:03:39] maodun: I know FactoryGirl exists and has such a distinction, but I was hoping to keep it simpler
[10:05:12] maodun: hmm, I'm getting an SQLite3::ConstraintException about bar_id may not be NULL
[10:05:33] maodun: yeah, I didnt notice that initially
[10:08:09] maodun: I'm a little confused how my db/schema.rb got set up with null: false, but I've fixed it now. Thanks
[10:39:32] maodun: I'm still having fixtures issues. I'm using labels to set up associations between my fixtures, but the when I test the association in rspec, the association comes up nil: "" is fine, but "user.address.zipcode" isn't.
[10:39:53] maodun: does fixtures support this type of reference? I see that user's address_id has been set
[10:40:14] maodun: I just can't figure out why address is returning as nil


[13:27:45] maodun: I want to route PATCHes and PUTs to different controller actions
[13:27:48] maodun: how can I do this?
[13:28:01] maodun: i tried put 'update', on: :member
[13:28:07] maodun: along with patch 'patch', on: :member
[13:28:20] maodun: but both verbs still get routed to my update method


[05:28:48] maodun: When I'm in the development env, I get a 404 on assets/application.css (assets/application.js, however, works just fine). What could be causing this?
[05:31:56] maodun: actually, sorry, scratch that, when I clear out assets/ it loads neither successfully
[05:32:11] maodun: axilaris: I know this sounds silly, but no, that was the difference. Should it?
[05:32:43] maodun: but for the dev env, I shouldn't need to do rake:assets:precompile, right?
[05:34:49] maodun: sorry, I know it may sound basic, but I've actually read the guide on the asset pipeline many times and I've never managed to get it to work in both production and dev ever since we migrated to 3
[05:35:13] maodun: if I don't precompile, public/assets should be empty, right?
[05:36:13] maodun: axilaris: well, app/assets/stylesheets/application.css does exist
[05:41:01] maodun: ah, I figured it out


[03:42:57] maodun: I'm trying to use a single query to generate an array with [, total_count] pairs
[03:43:14] maodun: Order.joins(:purchased_items).select("product_id, sum(count) as total_count").group("product_id").map {|o| [o.product_id, o.total_count] }
[03:43:31] maodun: I can make it work with product_id, but I don't know how to pull in the actual product name
[03:45:43] maodun: oh, I figured it out, nevermind


[12:54:54] maodun: I have a model: Order(float: cash_due, integer: user_id). I want to do a query that such that I can see the total cash due for all orders inputted by each given user. How can I do this?
[12:55:05] maodun: I've tried:"cash_due, sum(cash_due) as total_due").group("user_id")
[12:55:18] maodun: but the rails console only gives me cryptic feedback
[12:55:27] maodun: (Object doesn't support inspect)
[12:56:29] maodun: When I try poking around at the results from that at all, I just get "missing attribute: feedback"
[12:57:27] maodun: rvanlieshout: thanks, but I want a hash where I see the cash due for every user
[12:57:52] maodun: rvanlieshout: and I'm trying to do it in one query
[12:59:09] maodun: rvanlieshout: same deal, the result doesnt support #inspect
[12:59:52] maodun: that's what's making this hard for me to learn - I can't really get any sensible feedback in the console from my attempts
[13:00:15] maodun: same deal, "missing attribute: feedback"
[13:00:55] maodun: "ActiveModel::MissingAttributeError: missing attribute: feedback"
[13:01:11] maodun: oh? perhaps feedback is something on my model??? i need to look
[13:01:21] maodun: I had assumed this was something cryptic from rails
[13:02:42] maodun: rvanlieshout: so, thanks for pointing that out, feedback is indeed a text field in my model, but i don't think i've defined to_s myself...
[13:03:37] maodun: rvanlieshout: sorry, .first.attributes? on the group query?
[13:03:50] maodun: same problem
[13:04:59] maodun: rvanlieshout, i'm using 4.1.0rc1, could be related? maybe i'll try dropping back to 4.0 to see if there's a difference
[13:06:19] maodun: rvanlieshout: oh, well, I have overwitten init on my Order model
[13:06:28] maodun: the line that seems to be calling it is the beginning of my init
[13:06:53] maodun: def init; || = ''; end
[13:07:32] maodun: err, init is a hook i'm calling after_initialize
[13:08:56] maodun: rvanlieshout: so, it was definitely that hook that was crewing everything up. thanks
[13:09:34] maodun: working now :)


[13:52:23] maodun: I have an Order model which contains a transaction_id and a set of Transactions. How can I efficiently find all transactions such that no order has their transaction_id?
[13:52:56] maodun: aside from loading all orders and transactions and doing a select on the orders


[14:23:06] maodun: I have 3 models: Order, PurchasedItem, and Product. An Order has_many :products, through: :purchased_items. Assume order.product_ids = [1]. If I update order.product_ids = [2], what happens to the PurchasedItem record that was originally linking Product 1 with my Order?
[14:23:39] maodun: is it deleted? Or is the order_id on the purchased_item just set to nil?


[06:44:28] maodun: I have a MySQL table where entries have a unique identifier (not the id, something else, related to the day created: ie, something like 2013-12-21-001). When someone is about to create a new entry, the person needs to read the database, find the largest id for the given day, and increment it so that the new entry is unique. Then they can write the new entry
[06:44:54] maodun: The problem is I need some sort of locking so that people don't read the table at the same time and insert identical ids
[06:45:24] maodun: MyTable.transaction do; MyTable.lock; # read and then insert new row; end; isn't working
[06:46:02] maodun: pontiki: oh? Then I'm a little confused by the name
[06:47:30] maodun: I thought maybe the problem is that MyTable.lock is a read lock, so two users can read the existing id in parallel, and then sequentially write the same id to the db, thus resulting in duplicate ids
[06:48:51] maodun: pontiki: ah, so in my situation I should be setting some sort of app-wide global mutex instead of doing a transaction?
[06:51:37] maodun: pontiki: hmm, I'll keep looking into that. that's what I've been looking at, thanks
[06:54:40] maodun: pontiki: i think you're right, it looks like I want a "select ??? for update" lock


[10:44:14] maodun: I have a bunch of User models in my database. I now want to add a new validation: validates_uniqueness_of :username. I have several models in my database that violate this. After adding the new validation, however, calling .valid? on one of the (what should be) newly invalid but previously existing records returns true. What am I doing wrong?
[10:45:28] maodun: Let's say I have to models in my database: User<username: 'foo', id: 1>, and User<username: 'foo', id: 2>. They were saved there before the uniqueness validation was added. Now, having edited the model to add thew new validation, User.find(1).valid? still returns true.
[10:48:54] maodun: I'm trying to to modify the contents of a database to conform to stricter standards (which will be ensured by future model validations), and I thought just adding the new validations and then searching for invalid models would be the cleanest way to handle the situation, but it seems not to be the case


[04:14:24] maodun: I'm using nginx as a reverse proxy and nginx is setting X-Real-IP and X-Forwarded-For appropriately. I have rails configured to log remote_ip, but the remote_ip is always logged as (nginx's address). Is this the right behavior?
[04:14:56] maodun: If so, how can I get it to log the X-Forwarded-For IP? If not, what might I be doing wrong?
[04:16:19] maodun: Andrevan: I am asking a question about what the intended behavior of config.log_tags = [:remote_ip] is
[04:17:01] maodun: Andrevan: I would like to log the actual remote IP address
[04:17:23] maodun: as opposed to for all connections, since logging localhost for all my connections is kind of meaningless
[04:18:19] maodun: Andrevan: I see, so :real_ip will work?
[04:19:12] maodun: Fire-Dragon-DoL: no, as I'm trying to configure the logger, not deal with the ip in my controllers
[04:19:31] maodun: Andrevan: I see.
[04:21:38] maodun: Andrevan: That seems clear. I will double-check. I feel like I checked this in the past, but perhaps my memory is not serving me correctly
[04:35:12] maodun: so, HTTP_X_REAL_IP and HTTP_X_FORWARDED_FOR are properly set. What else does rails need to know?
[04:36:17] maodun: ah, but remote_addr is set to, perhaps that's the rub
[04:41:14] maodun: epochwolf: interesting, thanks. my config looks quite similar to yours. do you have config.log_tags set somewhere in your app?
[04:41:47] maodun: epochwolf: yeah, i'll post it, one sec
[04:46:43] maodun: epochwolf, Andrevan: thank you both for your help. this worked for me: config.log_tags = [proc { |request| request.env["HTTP_X_REAL_IP"]}]
[04:47:58] maodun: epochwolf: yeah, that's very interesting. I disabled my config.log_tags line a la your config, and it just stopped logging the IP altogether


[10:18:23] maodun: Is there a good way to do a where query where you want to test for an attribute's membership in a list? e.g., Person.where(status: in ['missing', 'dead'])
[10:19:03] maodun: ljarvis: argh, as soon as I typed that, I thought I should probably test that. thanks
[10:20:03] maodun: while I'm at it, what about Person.where(status: not nil)?
[10:20:42] maodun: oh, rails 4 does support not like that
[10:20:45] maodun: awesome, thanks
[11:44:41] maodun: I'm getting a "No route matches [PUT] /users" when I try to save a backbone model with url: '/users'. My config has 'resources :users' in it. What am I doing wrong?
[11:51:57] maodun: ah, I was using url instead of urlRoot in my backbone definition...


[19:22:42] maodun: using live streaming, is there any good way to check if is closed without actually attempting to write to it and catching an IOError?
[19:24:59] maodun: I'm going to guess that means no


[01:08:37] maodun: I'm trying to migrate to rails 4 and I'm getting a lot of ForbiddenAttributesErrors. Is there a good way to figure out specifically which attributes are causing the errors?
[01:08:48] maodun: some of my models have a lot, and it's pretty tedious to do process of elimination


[02:04:31] maodun: I have an XMLHttpRequest that's being made to my rails server, then abruptly aborted before rails hits the respond_to code block. Then my server seems to block on this. Why would this be and what should I do to avoid it?
[02:05:44] maodun: Basically I make a request to the server, the server sees the requests and sleeps for 10 seconds, and in that 10 seconds, I abort the request client-side. Then the server seems to hang when it wakes from the sleep and gets to the respond_to block


[00:51:27] maodun: With rails 4 attribute protection, I see calls like params.require(:user).permit(:name, :title). What do I do if my attributes are simply PUT as {'name': name, 'title': title, 'id': id}?
[00:51:38] maodun: params.permit(:name, :title, :id)?
[00:53:24] maodun: I get a ForbiddenAttributesError


[12:01:17] maodun: is there a good reason why time should have a usec method but datetime should not?


[06:04:23] maodun: rails is apparently planning on deprecating active_record_store. what is the recommend session store going forward?
[06:04:33] maodun: recommended*
[07:07:19] maodun: rails g migration doesn't work for me - the rails output tells me I can only do 'rails new'
[07:07:23] maodun: why is that?
[07:07:46] maodun: twelz: yes
[07:07:57] maodun: tewlz, pipework: i am in the project root
[07:10:30] maodun: hmm, so, ./script rails g works
[07:11:12] maodun: pipework: err, the problem came when I pulled from git (I know, I know)
[07:11:20] maodun: presumably this has to do with me working off edge
[07:11:28] maodun: so I'll just deal with it
[07:12:06] maodun: yeah, bundle e rails doesn't work either
[07:13:09] maodun: by, "doesn't work" I mean returns the same results as directly running rails
[07:14:31] maodun: Ok, thanks. In the meantime I'll just call script/rails
[07:21:56] maodun: pipework:
[07:23:48] maodun: pipework: what would mean more?
[07:28:00] maodun: pipework: thanks for the feedback, unfortunately I have to run. I'll dig into it later


[13:48:35] maodun: was self.table_name deprecated in rails 3.2?
[13:49:11] maodun: my code is functioning like that may be true, but some googling suggests that self.table_name is the appropriate thing to do in 3.2
[14:38:00] maodun: How does rails 4.0 performance compare with 3.2?
[14:38:24] maodun: rails 3.2 seems noticeably snappier than 3.0
[14:39:03] maodun: certainty: that seems improbable


[07:54:18] maodun: What's a good ruby equivalent for jQuery's $.post and $.get?
[07:55:01] maodun: I need to make a post request from ruby
[07:55:51] maodun: certainty: thanks


[14:30:11] maodun: I want to do a query returning all Employees whose name is neither 'Bob' nor 'Joe'. How can I do this elegantly?
[14:30:29] maodun: the inverse of Employee.where(name: ['Bob', 'Joe'])
[14:33:26] maodun: berty, derekprior: ok, I was hoping for something like the former solution, but I see that I'm stuck with the latter. thanks!
[14:33:44] maodun: is the same true of less than, btw?
[14:33:51] maodun: 'foo < ?', bar
[14:34:27] maodun: or is there something like where.less_than(foo: bar)?
[14:35:38] maodun: derekprior: thanks


[21:54:32] maodun: I'm getting this error:
[21:54:51] maodun: Ruby says it can't find the openssl file, but it's definitely there
[21:55:06] maodun: I followed the instructions here:
[21:55:14] maodun: What am I doing wrong?
[21:56:29] maodun: cableray: :(
[21:58:51] maodun: davidcelis: yes, the rvm ones
[21:59:11] maodun: cableray: on centos 5.5, compiled ruby via rvm
[21:59:54] maodun: davidcelis: i'm not sure.
[22:00:06] maodun: how would I tell?
[22:01:35] maodun: davidcelis: I did get this message after 'rvm pkg install openssl': Updating openssl certificates
[22:01:54] maodun: davidcelis: it uses yum, but i installed openssl via rvm
[22:02:13] maodun: since centos 5.5's openssl is apparently too old


[04:38:43] maodun: bundle exec rails c is pretty depressingly slow, like 10 seconds for me. Is the only way to speed it up to reduce gems in my gemfile?
[04:40:17] maodun: sevenseacat: I'm already at 1.9.3
[04:41:47] maodun: sevenseacat: interesting, i hadn't heard of this before. are there downsides?
[04:42:29] maodun: cool, thanks
[05:07:29] maodun: Antiarc: thanks


[15:55:41] maodun: I have an Order ActiveRecord with a serial attribute (which is a string). I have an array of strings (serials_to_check) that could potentially be serials matching those in the database. How do I efficiently select all strings in serials_to_check where no Order already has such a serial?
[15:57:51] maodun: basically, how can I do a where query with an "in" component?
[15:58:09] maodun: googling for prepositions is always tricky
[16:00:41] maodun: I'll try to put it more succinctly, how can I do the following: Order.where(serial in serials_to_check)
[16:02:13] maodun: elaptics: ah, thanks
[16:02:30] maodun: so it looks like Order.where(serial: serials_to_check) would work
[16:03:10] maodun: ok, cool, thanks


[04:57:52] maodun: I have a rails app that uses mysql. I have a script that needs to access both a mongo db and my rails db. I therefore added the mongo gem to my Gemfile. Unforunately, this has now caused my scaffolding to generate mongoid models instead of the typical ActiveRecord models. How can I disable this new behavior?
[05:01:47] maodun: nevermind, figured it out


[04:57:27] maodun: How can I configure rails to only accept requests from localhost?
[04:59:12] maodun: lighty: will that work with thin as well?
[05:00:08] maodun: lighty: ah, thanks


[13:20:20] maodun: How can I tell rails to send the precompiled .gz file for application.js?
[13:21:05] maodun: workmad3: oh, ok
[13:21:39] maodun: if rails sends a big file, like a 3 megabyte file, the other clients making requests will hang right?
[13:22:17] maodun: if so, then using a server for static server is pretty key
[13:22:26] maodun: s/static server/static content
[13:22:59] maodun: workmad3: ah
[13:25:04] maodun: workmad3: ah, ok, thanks. i figured as much, i've just avoided it because setting up nginx or apache seems a bit of a hassle
[13:25:11] maodun: but i guess it's needed at some point
[13:37:52] maodun: workmad3: ok, I'm using nginx to serve assets statically, but the .js file is still being sent, not the .gz file
[13:39:22] maodun: workmad3: already googling, wasn't going to ask :)
[13:52:22] maodun: workmad3: working now, thanks


[12:24:22] maodun: I have an Customer model and an Order model. Customer has_many Orders. An Order also has a timestamp. I need to grab all Customers with Orders which have a timestamp within a certain datetime range. Is the fastest way an Order.where('timestamp >= ? AND timestamp <= ?', start_time, end_time).map(&:customer)?
[12:25:57] maodun: Or rather: is there an obviously better way than my approach?
[12:27:00] maodun: awestroke: oh, I didn't know I could do that, thanks
[12:32:14] maodun: universa1: thanks. can the include come after the where?