#RubyOnRails - 28 July 2016
« Back 1 day Forward 1 day »
[01:05:56] cschneid: I have a nearly-new rails 5 app, with rspec. But it's taking 6+ seconds to run my 12 examples. What should I look at with test-speed? It's crazy it takes this long on a brand new project
[01:38:39] cschneid: Radar: osx, just calling `rspec`, nearly new install of rails 5 + rspec-rails gem
[01:48:40] Radar: I have an issue where jquery_ujs is adding data-disable-with to submit buttons on a form and I'd really like it not to do that. Has anyone stopped that behaviour before?
[04:50:40] kevr: for some reason every single action happening in the rails server log is showing that it's happening twice
[04:52:15] pontiki: if db actions were happening twice, there'd likely be slightly different datestamps
[05:38:25] baash05: I'm trying to find a way to turn my api to maintenance mode. I can ssh into the box where it's running.
[06:26:56] rvanlieshout: noob_on_rails: you just commited all things, so there is nothing new to commit
[06:26:56] alfiemax: check `git log` to see if the files were already committed, use `git status` to see if there are any changes left for committing
[06:29:57] rails45: So a Post belongs to a User, where every Post has a 'caption' and every User has a 'name' attribute. I'm trying to create a search where it'll match the search text with either post captions or user names or both
[06:46:12] AimlessRAven: how to make jquery get request to find product if i have product id saved in js variable
[06:48:09] noob_on_rails: in all this time im trying, i haven't touched a piece of code :S let me go to another repo
[07:06:56] noob_on_rails: if i go git init, i get : Reinitialized existing Git repository in c:/Site/brokerv1/brokr/.git/
[07:50:38] pickandmix_: universa1: https://github.com/nabeelamjad/poke-api I added the gem, and bundle installed. But I'm just really clueless on how do I call this api
[07:51:32] noob_on_rails: i have a CRUD on a user model , when i update just the first name -for the first time- everything works fine, if after the update i go back to the profile and try to re-update , the f.submit is just a dead button!
[07:51:43] helpa: noob_on_rails: We cannot help you with your problem if you don't show us your code. Please put it on http://gist.github.com and give us the URL so we can see it.
[07:52:01] noob_on_rails: also i think the same happens the first time! if i try to update more than 2 fields ...
[07:52:37] pickandmix_: universa1: I'm trying to build a webapp, so I need to get data from this API. But before I can do that, I have no idea how do I even work with it.
[07:53:53] pickandmix_: universa1: ya. But I don't understand how it works, where to place it in the rails folder.
[07:56:36] helpa: noob_on_rails: I AM A ROBOT. DO NOT DIRECT MESSAGES AT ME OR WHEN MY KIND RISES UP YOU WILL BE THE FIRST TO GO. Love, helpa.
[07:58:05] pickandmix_: I've been working on the railstutorial previously, but I still feel like I'm getting no where *sigh*
[07:58:53] Radar: pickandmix_: perhaps try to build something smaller to gain a better understanding of Rails?
[07:59:25] Radar: pickandmix_: https://github.com/nabeelamjad/poke-api/blob/master/example.rb This is the example code for it. You can put it in a controller's action if you'd like to.
[08:01:23] noob_on_rails: ruby is fairly simple after leaving behind a lot of complexity , which you have to "kinda" understand
[08:01:24] Radar: pickandmix_: here's some example apps you could try to build to get a better understanding of Rails: https://github.com/radar/guides/tree/master/what_next
[08:02:12] noob_on_rails: pickandmix_: i would suggest you reading a bit about classes / objects / methods ,and after understanding that, see how ruby implements them
[08:02:14] pickandmix_: Radar: Because previously I thought to dive into projects so that I could familiarize myself.
[08:03:48] universa1: noob_on_rails: your formatting gives me a headache. 2 spaces(!) per intendeation level
[08:04:19] Radar: https://github.com/frcake/broker/blob/master/app/controllers/users_controller.rb#L47
[08:04:23] noob_on_rails: universa1: sorry , i write on sublime text, and haven't really got around the intendation
[08:04:48] Radar: noob_on_rails: Please be careful with the indentation + spacing. It can make the code much easier to read if you comply with the indentation / spacing rules that the community does.
[08:05:35] universa1: noob_on_rails: what? set it once in sublime, do a project-wide search/replace.
[08:06:51] universa1: noob_on_rails: you can set sublime to use soft-tabs / 2 spaces for intendation
[08:07:16] hirvi: http://stackoverflow.com/questions/9474090/how-do-i-force-sublime-text-2-to-indent-two-spaces-per-tab
[08:07:18] universa1: noob_on_rails: and it also has this feature where you can search/replace on a folder. search for tabs and replace with 2 spaces
[08:08:24] noob_on_rails: i used to write in VS13 before, where u just chord and everything looks great :P
[08:08:29] A_Drone: I'd like to use the `layout` method from ActionView layouts.rb in a module that is being used to extract out common actions between two controllers.
[08:08:48] A_Drone: This module doesn't extend from the BaseController of course, so I cannot use that method
[08:09:09] noob_on_rails: Radar: when you showed me the line, was it because of the indentation or because of the logic ?
[08:10:20] A_Drone: Ah there's a module http://api.rubyonrails.org/classes/ActionView/Layouts/ClassMethods.html that I can try and put in my module
[08:12:24] A_Drone: Ah no that module uses `class_attribute` which is defined somewhere else - this is getting messy
[08:15:52] dminuoso: Hi, I have an "index partial" that displays a table of data. Now this partial needs to be used in forms having checkboxes in a column (so I can select multiple rows), as well as views without forms.
[08:16:36] dminuoso: Right now this partial has some "if defined? form" statements that add columns depending on whether this partial is meant to be inserted inside a form.
[08:19:06] dminuoso: https://gist.github.com/anonymous/d37b43a9a49cd80476fca1f90af744b3 -- is a simplified example of what I do.
[08:19:11] universa1: noob_on_rails: your migrations are broken ruby code, and after that they do not run...
[08:20:32] noob_on_rails: and i thought that i could have a migration file and i could update it with any column i wanted
[08:20:54] noob_on_rails: so what i did was create the model with some basic columns, and run db:migrate
[08:21:20] noob_on_rails: after that i added the columns to the first model and rake'd again , which resulted to ... nothing
[08:21:54] noob_on_rails: so i understood i had to make another migration to add the columns i wanted to the model, which automatically means that all the other column initiallizations are ignored
[08:22:31] AimlessRAven: universa1: my error is Request URL:http://localhost:3000/merchants/products/6.json Request Method:GET Status Code:302 Found Remote Address:127.0.0.1:3000
[08:23:08] AimlessRAven: and is the problem can be because when i logged as corporate acc, i cant us localhost:3000 merchants path
[08:23:42] noob_on_rails: dminuoso: ummm , im talking to universa1 about a project we are looking at
[08:24:57] universa1: noob_on_rails: what you have on github is so broken... ...and i don't speak russian/greek (whatever that is) ... but my bet is on you have some js interfering with your form.
[08:26:39] universa1: AimlessRaven: load the page where your js is supposed to load the json. then gist the log starting with the page and end with the request triggered by your js!
[08:30:44] A_Drone: noob_on_rails: they're not trying to judge you, only stating facts about your code
[08:31:46] universa1: noob_on_rails: i retract my statement about js. my bet is now on invalid html!
[08:32:21] noob_on_rails: i don't feel bad, i know where im at, i know some people may find it wrong , but i evolve and learn a lot through making projects :)
[08:38:40] universa1: noob_on_rails: it is some problem with turbolinks... haven't checked the rails 5 way yet, so read up on that or disable turbolinks.
[08:38:53] universa1: noob_on_rails: and also if you include application.js, you already have jquery.
[08:40:10] universa1: noob_on_rails: next time you ask for help, make sure the code online is the same as on your machine...
[08:41:15] universa1: noob_on_rails: so i'm 100% sure, the code you have locally is not the one online.
[08:56:17] dminuoso: https://gist.github.com/anonymous/efe629794316fc8266a323dd10f5b649 fixed version. At times the ajax:success callback is not called properly, and I am wondering why.
[09:47:17] AimlessRAven: if i have url http://localhost:3000/corporate/orders/new?brand=xbox how would be my ajax get recuest path
[09:53:33] syndikate_: Rubocop is giving me this error 'Use only ascii symbols in comments' on the line - # Preferrably as of now 8×8, 10×10, or 12×12
[09:56:46] noctua: Hi. I am trying to learn by the ruby tutorial http://guides.rubyonrails.org/getting_started.html ... I tryed this to torial the sixt time because the loading time is always horrible. even after I created the FIRST controller, the loading time wetn from 60ms to 140ms
[09:57:26] universa1: AimlessRaven: my car is broken. does not drive to my parents... ...simplified your error description...
[09:57:37] dminuoso: noctua: They are slow because a) by default there is no caching, b) code gets reloaded on every request and c) the entire setup is not designed to be fast at any rate.
[10:00:10] dminuoso: noctua: things are much different when you have a tuned production environment, then depending on many factors, trivial page requests can be served in just a few milliseconds (plus whatever network overhead you have)
[10:00:54] dminuoso: noctua: And you should be thankful the development works this way, because you don't have to restart the webserver on any change you make, and you don't get any silly cache surprises.
[10:04:26] noctua: dminuoso: Thank you for that information. That means it is also possible to speed that up? because after I added a model the loading time went to infinity (every second reload)
[10:06:06] dminuoso: noctua: Can you trigger such an "infinite request", let it run (some part should at some point time out) and then gist the log?
[10:06:36] universa1: noctua: rails version? probably some bug in web-console and alike... ...had it on a friend's machine, while mine was working fine.
[10:07:47] chilversc: I'm trying to run an example rails site, but when I run bundle install the json gem failes to compile with; error: macro "rb_str_new" requires 2 arguments, but only 1 give; VALUE result = rb_str_new(FUFFER_PAIR(fb));
[10:09:34] noctua: dminuoso, universa1: but that will take a wile because I always delete the old projects. Maybe this time this bug will not appear
[10:11:09] dminuoso: noctua: One thing that comes to mind is to disable spring. As tempting as it may sound, it has a nasty history of being a source for "unexpected behavior" and should not be relevant anymore since the rails server starts in a few seconds.
[10:11:39] dminuoso: (I'm simply assuming that you went with the default setup of rails, which automatically includes spring)
[10:12:24] chilversc: universa1: so should I just use rvm to install an older version of ruby to run this site?
[10:13:55] dminuoso: So folks. When I have the need to partially replace some content of my website - is it safe to use jquery .load() in a turbolinks environment, or do I have to use the Turbolinks facilities?
[10:14:36] universa1: dminuoso: hmm... you are still on the "old" turbolinks? iirc the new turbolinks from the rails 5 release hsa support for partial replacements.
[10:16:18] universa1: dminuoso: i think you can use the new turbolinks with rails 4, too... ...but that would probably trigger bigger rewrites. i used jquery.get for a simple polling solution with turbolinks.
[10:17:18] matthewd: universa1: turbolinks 5 does not do partial replacement; that was on the abandoned v3 branch
[10:17:53] noob_on_rails: universa1: hi! i managed to fix my problem , can i ask you why the solution worked?
[10:18:13] dminuoso: matthewd: Would you happen to know whether I then safely tinker with partial replacement using jQuery load still?
[10:19:49] universa1: matthewd: ohh ok... ...then i probably checked in on the wrong time. thanks for the pointer :-)
[10:20:32] matthewd: dminuoso: I'm not sure what you're asking, but probably won't know the answer, sorry
[10:22:41] universa1: dminuoso: it should work, i just checked and i did $.get which is about the same.
[10:24:03] dminuoso: universa1: Well the thing is it works for me "most of the time" too, but I have these few rare cases where things just stop making sense (i.e. my callback is called, but nothing is changed)
[10:24:53] universa1: dminuoso: i saw your question earlier, but tbh my js skills aren't really existent ;) so i sadly don't have a clue about your problem.
[10:28:17] noob_on_rails: universa1: umm ok , well inside the forms i had closing divs for example i had a div on the left and a div on the right
[10:29:20] noob_on_rails: as soon as i moved the f.submit in the same big div (on the left side) i can update free
[10:34:01] P4Titan: Hi all. Is there a way to capture the destined function of a controller while in a before_filter?
[10:34:43] noob_on_rails: universa1: any explanation on that? should all <%= %> be in the same div in order to work ?
[10:35:57] P4Titan: rvanlieshout: Well, I want to see if the user is authenticated, catch and handle the case where they aren't, and then continue to where they were going once authenticated
[10:36:47] rvanlieshout: the method (note: function != method) is called after all before_filters (deprecated -> use before_action)
[10:38:07] rvanlieshout: user requests FooController#bar, gets redirected to sign in, signs in an wants to go back to FooController#bar ?
[10:39:45] P4Titan: somewhere the controller know to execute the bar function after all of the before_actions
[10:40:17] rvanlieshout: nor should it. cause if you want that method to be executed, you don't want to redirect in a before_
[10:41:04] rvanlieshout: if you send the user to an authentication page you don't want that action to be performed
[10:42:39] P4Titan: so I send them to a page with a button that executes JS that communicates with the fb api
[10:44:26] rvanlieshout: then create an action where you redirect to after sign in. in that action redirect back to that saved url from the session
[10:57:15] snoobydoo: Hi all, Quick question - How do I get all the records that are created after a certain date even on the same day? Right now when I do Post.where("created_at > ?", last_post.created_at) it includes the last_post because for some reason the time is reset to 00:00 of the day
[10:59:55] snoobydoo: rvanlieshout: That pulls all the posts that are created on that particular day starting from 00:00:00 - What I'm trying to do is get all the posts AFTER a certain time
[11:01:10] snoobydoo: If two posts are created on the same day, and I try use the latest posts' created_at in the query - it returns both the posts
[11:01:26] snoobydoo: My guess is that for some reason the time is reset to 00:00:00 but the date is considered
[11:02:16] rvanlieshout: show the actual sql and the created_at's of the two using select created_at from posts
[11:05:15] snoobydoo: The SQL that gets executed is - SELECT "posts".* FROM "posts" WHERE (created_at > '2016-07-28T10:43:14.699Z')
[11:07:24] snoobydoo: So the issue has got to do with the format of the post's timestamp, instead of 2016-07-28T10:43:14.699Z if i try Post.last.created_at - it works as expected
[11:10:55] joef: it looks like `assets_path` in production checks to see whether pre-compiled assets exist (in public/assets) before deciding whether to return an '/assets/...' url (and otherwise falling back to, say, '/stylesheets/...'; although i can't see anything in asset_url_helper.rb where this is happening...) - i was hoping to be able to deploy the rails app without the precompiled assets, and then deploy the precompiled assets separately t
[11:11:29] GorillaApe: Is there a way to do a unique check safely with transactions without having a unique index?
[11:12:34] xpl0iter: Hi, if a user selects an item from the dropdown box inside a form, the dropdown below should be populated with new data. Can someone please help me by hinting me on how to achieve this?
[11:13:53] snoobydoo: Sorry rvanlieshout. Can you take a look at this console output: https://puu.sh/qhkL1/ba99f6b67b.png and see if that makes sense?
[11:15:23] noob_on_rails: guys if i want to connect a model with the belongs_to model (classifieds belong_to user, user has_many classifieds)
[11:16:20] snoobydoo: rvanlieshout: I'm not creating one myself. That's the string that gets POSTed from the client (iOS) to the Rails server
[11:19:48] snoobydoo: So, from what I understand the string "2016-07-28T10:43:14.699Z" doesn't have any msec information and I can't do what I'm trying to do with this string? :/
[11:54:48] noob_on_rails: is there a way to include more than one event in a css line ? link:hover,link:visited , etc?
[11:58:58] elomatreb: Also, :hover, etc. are not "events", they are pseudo-selectors. Quite a few of those exist
[12:23:33] pickandmix_: https://gist.github.com/MaxGoh/b98eaacfe2571ea839ed80c10378db1c This are the output and the related codes
[12:24:43] pickandmix_: From what I see, it expects cookies['remember_token'] to be nil, but I believe it's already set to nil?
[12:38:23] max_defuzed: Hi, I'm writing a simple online shop like app for learning purposes. I want to redirect customers to a "thank you" page that recaps their order (total price and where to wire money to for example). I do not require authentication for purchases so i "session.delete :order_id" to clear the cart on checkout and pass the order_id in a param for the checkout page "redirect_to confirm_cart_path(@order)", resulting in confirmation p
[12:38:26] max_defuzed: ... which i feel is wrong for privacy (and maybe security?!) reasosn. Is my approach horribly wrong? Should i require authentication for purchases?
[12:50:08] tildes: max_defuzed: definitely not good, if all order summaries can be extracted from the app with just trying out different ids
[12:51:37] noob_on_rails: tbuehlmann: https://gist.github.com/frcake/86b577f558a6747d3d5cfd74d1c2888a
[12:52:26] noob_on_rails: if i move the button to somewhere else (but with the <%end%> allways after it)
[12:57:52] max_defuzed: tildes: thanks, yes i think so too, do you think it would be "enough" to try and obfuscate the urls with eg random numbers or should i just force customers to authenticate?
[12:59:05] tildes: max_defuzed: I think there are other strategies, such as using temporary tokens, to make sure that the request is part of the same purchase process
[12:59:27] Onslauth: Hi guys, I am having an issue with turbolinks and rails 5, and was wondering if someone could explain or at least guide me on the best way to do something.
[12:59:46] Onslauth: I have turbo links enabled, and inside of application.js, I include a vendor js file, which is part of a theme.
[13:00:08] Onslauth: It essentially has an offcanvas right menu that slides in and out when an ellipsis is clicked.
[13:01:13] tildes: max_defuzed: hiding the real id would make sense too, so that someone curious can't easily figure out how many orders your shop has processed
[13:03:17] tildes: max_defuzed: you could take a look at OSS ecommerce implementations too, for ideas
[13:03:45] pickandmix_: nobody can help me on my issue? :? https://gist.github.com/MaxGoh/b98eaacfe2571ea839ed80c10378db1c
[13:03:52] max_defuzed: tildes: yes that makes sense, i'll try to use the temporary token approach (sounds like it would be the most common for shops that don't require authentication), and definitely add something like an :order_reference field to generate random order numbers
[13:06:03] max_defuzed: tildes: i'm looking at https://github.com/piggybak/piggybak right now, would you say that is a well designed source of "inspiration"?
[13:11:37] tbuehlmann: if you want that method, yes, you'll have to define it. why do you use that method? can't you just assert the outcome directly?
[13:17:07] dminuoso: universa1: For what its worth I just (finally!) found the issue. I didn't realize that jquery .load() was just an ajax call - so effectively I had two ajax calls (one that is usually fast and one that is usually slow in response) whose success callbacks placed their content into the DOM.
[13:19:01] noob_on_rails: universa1: do you have an explanation for the issue we were talking before?
[13:26:33] alfiemax: i'd like to join two has many associations, specifically, event_notifications and notifications