|
Fillerbunny posted:
The option is class_name: http://guides.rubyonrails.org/association_basics.html#detailed-association-reference
|
# ? Feb 24, 2014 18:05 |
|
|
# ? May 29, 2024 11:21 |
|
Cocoa Crispies posted:The option is class_name: http://guides.rubyonrails.org/association_basics.html#detailed-association-reference You're right, sorry. That was a typo in my example code. But my original problem is still: how can I keep these properties separate in the database? How can I get a different record from SomeObject.first.descriptions.first than from SomeObject.first.instructions.first ?
|
# ? Feb 24, 2014 19:23 |
|
Fillerbunny posted:You're right, sorry. That was a typo in my example code. If you want to use a polymorphic association, you're going to just use an integer in the wikientry table to store the entry_type.
|
# ? Feb 24, 2014 19:37 |
|
e: ^^ or an int value.Fillerbunny posted:You're right, sorry. That was a typo in my example code. That seems like something more for scopes than for polymorphism. As you've got it now, the only things rails sees is is a wikiable, not which association it's attached to. Would it be so bad to create a "wiki_type" column (in addition to the wikiable_type column) in the WikiEntry class, then do: Ruby code:
kayakyakr fucked around with this message at 19:43 on Feb 24, 2014 |
# ? Feb 24, 2014 19:40 |
|
kayakyakr posted:e: ^^ or an int value. Nope, that's not so bad at all. In fact, that's exactly what I was looking for. Normally I would go with an enumerated type, but I also like to be able to tell what type a thing is simply by looking at the records in the table, so I'll go with the string value. Thanks for your help, guys. I haven't worked with scopes much/at all yet, so here's a good reason to read up on them.
|
# ? Feb 24, 2014 19:59 |
|
Fillerbunny posted:Nope, that's not so bad at all. In fact, that's exactly what I was looking for. Normally I would go with an enumerated type, but I also like to be able to tell what type a thing is simply by looking at the records in the table, so I'll go with the string value. must admit, this is not exactly scopes, just taking advantage of arqi and the fact that you can define sub-methods on an association. I'm not even really sure what defining sub-methods is termed, but since traditional scopes have gone the way of the dodo, I'll call this scoping. e: and this is why I dislike TDD. I spend as much time figuring out why the test suite is doing something as I do actually programming. In this case, I've got an embedded document that I'm not creating (yes yes, i'm using mongoid, so lame of me), and I'm not specifying in the factory, which is showing as nil in console and when i drop into debug, but exists when the test suite tests for its existence. e2: ah, something that mongoid::matchers was doing to me. alright, expects and asserts syntax for any manual tests kayakyakr fucked around with this message at 22:01 on Feb 24, 2014 |
# ? Feb 24, 2014 20:19 |
|
The Milkman posted:Because I didn't know about timeout This looks like the kind of code that if it breaks is terrible. Why not just calculate the current image based on the time. Something like code:
|
# ? Feb 26, 2014 06:39 |
|
Popper posted:This looks like the kind of code that if it breaks is terrible. Yeah, that was my original idea. What I ended up going with was this (based on Cocoa Crispies answer): code:
|
# ? Feb 26, 2014 18:16 |
|
I'm cross-posting this from the general programming thread: I am brand new to web development as a whole, and am trying to put together a simple application for patient checkin at work. I crated a rails scaffold for providers. The model has 4 accessible fields: Name Time1 Time2 On the providers/index page, I want to add a button at the end of each row that will populate time2 and keep me on the same page. So I would have something like: Name email Time1 Time2 Actions Fred fred@aol.com 12:00 [Time2] Joe joe@msn.com 1:00 [Time2] When the user clicks on the Time2 button, it should populate time2 for that record and then reload/refresh/requery the page to display the new information. My button on the form is code:
Any help?
|
# ? Feb 27, 2014 17:47 |
|
Phummus posted:I'm cross-posting this from the general programming thread:
|
# ? Feb 27, 2014 19:36 |
|
Phummus posted:My problems are that I don't know where to define set_time2, and I don't know how to manage the routes so that the user stays on the same page. 1) not sure what time1 and time2 represent, but you should use more descriptive column names and, depending on the purpose of the time1 and time2 fields, you may need to do a bit more in depth data modeling. 2) You can define your routes like: Ruby code:
Ruby code:
Ruby code:
Ruby code:
|
# ? Feb 27, 2014 20:06 |
|
kayakyakr posted:1) not sure what time1 and time2 represent, but you should use more descriptive column names and, depending on the purpose of the time1 and time2 fields, you may need to do a bit more in depth data modeling. This is just a test. My actual data model/database and application have useful names kayakyakr posted:2) You can define your routes like: kayakyakr posted:You would then add to participants controller This is the mehtod that does the redirect? kayakyakr posted:
Again, not sure what is happening here either. I've gone through Hartl's tutorial on Rails, and I feel like I'm still missing a big chunk of knowledge. When I implemented these changes, and load providers/index, I get the error: no block given (yield) on the route: code:
Phummus fucked around with this message at 20:24 on Feb 27, 2014 |
# ? Feb 27, 2014 20:20 |
|
Phummus posted:I'm already at a loss as to what this is doing. If I read it correctly its saying on an HTTP Post call the 'time' method defined below? You need to read this guide: http://guides.rubyonrails.org/routing.html, specifically section 2.10 Adding More RESTful Actions. Phummus posted:Again, not sure what is happening here either. And this API doc: http://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to Phummus posted:I've gone through Hartl's tutorial on Rails, and I feel like I'm still missing a big chunk of knowledge. Yes, you are. Learn to rely on the official rails guides and API docs, they are very, very good. "Phummus posted:When I implemented these changes, and load providers/index, I get the error: Member is a symbol. ':member' and not just 'member'. kayakyakr fucked around with this message at 20:34 on Feb 27, 2014 |
# ? Feb 27, 2014 20:32 |
|
Well there's some progress. now that I've put the : in place rails starts and clicking on the botton doesn't throw an error. It does, however send me to /providers/5/time 5 being the index of the row I clicked on and time being the route defined in routes.rb? When I go back to the index page, Time2 is not populated. So it is still taking me off the page and isn't setting the time. I'll pick up those two links you mentioned to see if it lights any bulbs.
|
# ? Feb 27, 2014 21:24 |
|
Let's review what you've got. You've: 1. Created a controller method, time, to handle populating time2 2. Created a route which directs requests from the network to that method If you haven't changed it, this is the body of that method: code:
What is this method not doing?
|
# ? Feb 28, 2014 00:11 |
|
Molten Llama posted:
I didn't create any new controllers, the only controller I have is for providers. The method is for providers, so my method uses providers instead of participants. It redirects me to a new page. I assumed it would be redirecting me to the participants/index page, however, when I invoke it through the button click, it redirects me to providers/{someindex}/time. It does not update any of the database fields.
|
# ? Feb 28, 2014 14:01 |
|
Phummus posted:I didn't create any new controllers, the only controller I have is for providers. It does not update any of the database fields because you haven't programmed any updates in. Rails does a lot of things for you, but it isn't magic. The redirect_to should be redirecting to the index page. try: Ruby code:
|
# ? Feb 28, 2014 15:43 |
|
I have a set of models that all need the same validation code (just checking a common field value against a controlled vocabulary). I'd prefer not to repeat this code in every one of the models. I created a mixin module for the vocabulary itself, but I don't think the validations can be in a mixin, can they? Is my best bet to put a new superclass with that validation between ActiveRecord and my models? Or should I not be sweating a single line of repeated validation code?
|
# ? Feb 28, 2014 15:52 |
|
Peristalsis posted:I have a set of models that all need the same validation code (just checking a common field value against a controlled vocabulary). I'd prefer not to repeat this code in every one of the models. I created a mixin module for the vocabulary itself, but I don't think the validations can be in a mixin, can they? Is my best bet to put a new superclass with that validation between ActiveRecord and my models? Or should I not be sweating a single line of repeated validation code? Read through: http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
|
# ? Feb 28, 2014 16:59 |
edit: never mind, I'm retarded I need Pardot or someone else who is good at postgres to help me inserting a string with quotation characters Ruby code:
code:
code:
A MIRACLE fucked around with this message at 17:16 on Mar 10, 2014 |
|
# ? Mar 10, 2014 16:56 |
|
A MIRACLE posted:I'm retarded
|
# ? Mar 10, 2014 19:22 |
Does activerecord have a way to do a mass row insert?
|
|
# ? Mar 10, 2014 19:59 |
|
A MIRACLE posted:
No. Anyhow, I know that activerecord-import does approximately what you want to do, but I haven't personally used it. Caveat emptor.
|
# ? Mar 10, 2014 20:18 |
|
Doing it as a single mass insert is the fastest way that I know of to do it.code:
|
# ? Mar 10, 2014 20:30 |
Smol posted:No. Anyhow, I know that activerecord-import does approximately what you want to do, but I haven't personally used it. Caveat emptor. I looked at this but decided to just raw-dog it since we're only going to use it in one place. And I didn't really want to loop through 70,000 users or so in vanilla activerecord
|
|
# ? Mar 10, 2014 20:35 |
|
A MIRACLE posted:Does activerecord have a way to do a mass row insert? You're doing it right. I assume that you figured out what your issue is and I don't need to point out that you're calling quote_string for each user_id. By the end of that loop, you've quoted the string 5 times for a total of 32 apostrophes. Powers of 2 are a bitch. And depending how your test case is written, what that should read as is "These pretzels... they''re makin'' me thirsty!" Escaping ' in postgres is written as ''. e: also you should do it in batches. test out your use case between 100, 500, 1000, etc batch sizes, you should find a sweet spot. kayakyakr fucked around with this message at 20:38 on Mar 10, 2014 |
# ? Mar 10, 2014 20:35 |
|
A MIRACLE posted:I looked at this but decided to just raw-dog it since we're only going to use it in one place. And I didn't really want to loop through 70,000 users or so in vanilla activerecord Good choice.
|
# ? Mar 10, 2014 21:41 |
|
$$ strings are neat:code:
code:
|
# ? Mar 10, 2014 21:47 |
|
So I am trying to debug a massive slow down in an application.code:
I have a test for this that does EXACTLY the same method on exactly the same parameters, on exactly the same data. It takes 60 seconds. Any ideas?
|
# ? Mar 11, 2014 19:41 |
|
Legacyspy posted:So I am trying to debug a massive slow down in an application. 60 seconds is still too long to churn. How big is your production database? Does your test DB have just those 200 items while your production have more? Do you have indexes set for those tables? Things you should consider when dealing with that much data: update with raw SQL instead of churning through active record. Update in batches. Select and update in the same step instead of selecting each of 200 items and then updating each of 200 items. If you can't get it to < 2 seconds if you're doing AJAX or < 1 second if you're doing classic form post, then you need to push that off into a background task (I recommend sucker punch as it runs threaded inside your server).
|
# ? Mar 11, 2014 21:39 |
|
Legacyspy posted:So I am trying to debug a massive slow down in an application. What does New Relic say it's spending its time on? If it's slow in development, you can use developer mode.
|
# ? Mar 11, 2014 22:18 |
|
Legacyspy posted:So I am trying to debug a massive slow down in an application. Show us the query (or queries), your schema, how many rows there are in the respective tables and which database you are using. If possible, output from PostgreSQL's EXPLAIN ANALYZE or MySQL's EXPLAIN will help as well.
|
# ? Mar 11, 2014 22:26 |
|
I am going through: http://alexpotrykus.com/blog/2013/12/07/angularjs-with-rails-4-part-1/ this tutorial to set up Angular with rails4.02. I am getting stuck with "ActionController::UnknownFormat" after I set up the api to deliver JSON in routes and the controller. I can access the JSON at /api/risks but when I try and access the root after setting up my RiskCtrl it gives me the UnknownFormat error. EDIT - I figured out the issue I was having, I had my risks index as my root, instead of having a different page being my root and calling on my Risks API. Sucks to suck I guess Newbsylberry fucked around with this message at 18:24 on Mar 13, 2014 |
# ? Mar 12, 2014 21:15 |
|
Terribly sorry for the double post, but has anyone had any success and would be kind enough to explain using has_many, belongs_to, etc. with angular as your front end? I have found a couple of resources online, and I am guessing I need to do it through my services, but it isn't really clicking for me. If anybody has been through this themselves and can help me figure it out, I would throw an upgrade their way.
|
# ? Mar 13, 2014 18:24 |
|
Coming back to Rails development and I see that unicorn is included in the default Gemfile now. Is that the preferred web server or do people still use Thin / Passenger?
|
# ? Mar 16, 2014 18:04 |
|
xtal posted:Coming back to Rails development and I see that unicorn is included in the default Gemfile now. Is that the preferred web server or do people still use Thin / Passenger?
|
# ? Mar 16, 2014 18:23 |
|
xtal posted:Coming back to Rails development and I see that unicorn is included in the default Gemfile now. Is that the preferred web server or do people still use Thin / Passenger? Thin seems to be falling out of favor because Puma does the same thing for MRI without having to rely on EventMachine and does more when you hook it up to jruby or rubinius. Unicorn is still my standard, but if you want websocket support, you should also use a server like Puma.
|
# ? Mar 16, 2014 18:40 |
|
Suppose that a user is signed into a rails app (with the devise gem) with an ember front end. I want to be able to log the user out after a certain amount of time (probably a little longer than the length of a regular workday) regardless of activity (this is key), and have the user come in the next morning with the login screen on their browser. I've had some success using a modification of the method here (https://www.coffeepowered.net/2013/09/26/rails-session-cookies/), modified such that I don't refresh the ttl. This partially works, but (1) it doesn't automatically redirect to the login screen, and (2) because of the way some of the ember stuff is set up, only upon clicking certain links does it redirect to the login page. I was thinking of making a worker that checks every minute or so to see if a user has been logged in for > x.hours, but I was discouraged, since it would likely use too many resources. Is there another approach that would work well for this that I haven't thought of yet?
|
# ? Mar 16, 2014 22:32 |
|
yoyodyne posted:Suppose that a user is signed into a rails app (with the devise gem) with an ember front end. I want to be able to log the user out after a certain amount of time (probably a little longer than the length of a regular workday) regardless of activity (this is key), and have the user come in the next morning with the login screen on their browser. I've had some success using a modification of the method here (https://www.coffeepowered.net/2013/09/26/rails-session-cookies/), modified such that I don't refresh the ttl. This partially works, but (1) it doesn't automatically redirect to the login screen, and (2) because of the way some of the ember stuff is set up, only upon clicking certain links does it redirect to the login page. Devise includes a "remember_for" option that you can set on the model. ex: Ruby code:
|
# ? Mar 16, 2014 22:46 |
|
|
# ? May 29, 2024 11:21 |
|
yoyodyne posted:This partially works, but (1) it doesn't automatically redirect to the login screen, and (2) because of the way some of the ember stuff is set up, only upon clicking certain links does it redirect to the login page. I could be wrong, but it sounds like you're all set from the cookie side, and you just need to detect whether the user is logged in or not from the javascript side, and redirect to the login page once their session has expired. I think you'd probably need some sort of "heartbeat" type call on a controller that could tell you whether you have an active session, and ping it every minute or so to see if your user is still active. If you don't get a "logged-in" status from that service, redirect to the login page.
|
# ? Mar 17, 2014 11:35 |