|
I think it just takes some time to understand it. It's not really namespaces so much as figuring out what's been included where. If you're writing a new class in Ruby you have to realize that you're not going to have direct access to any methods unless you include the module that they're in or they're methods in the class itself (or in its parent tree). That said, trying to use view helpers outside of views can be frustrating.
|
# ? Apr 5, 2012 03:25 |
|
|
# ? May 15, 2024 10:24 |
|
prom candy posted:That said, trying to use view helpers outside of views can be frustrating. It's mostly a documentation problem. Since it's not written down anywhere official, it took like an hour of googling to figure out that the named route helpers were contained in Rails.application.routes.url_helpers (a module returned by a class returned by a class returned by a... I want to say module?). Looking at the rails source wasn't any help either, because it's all hidden behind 7 layers of magic and abstraction.
|
# ? Apr 5, 2012 05:51 |
|
Try Sinatra. It does much less than rails so it's easier to understand. I use sintra and sequel for most things these days. http://www.sinatrarb.com/ http://sequel.rubyforge.org/ Pardot fucked around with this message at 22:20 on Dec 8, 2013 |
# ? Apr 5, 2012 06:35 |
|
CanCan talk: I have a class that has multiple types to it. It is all the same type though except for a field that helps tell the rest of our system how to handle it. So there is only 1 model, but several uses. As such, we want to limit 3 types of user roles to different permissions for the 3 types. My main option is to create a model to further refine each type. However I'd like to know if I can do a test on the type without having to put stuff in each of the RESTFUL actions. Ideally I'd like to do this: code:
code:
|
# ? Apr 5, 2012 16:37 |
|
When you say that you have one model but several types are you talking about Single Table Inheritance? is there a class called TypeA? The code that you reference for comments is an example of passing a block to a CanCan call in order to further refine access: code:
code:
|
# ? Apr 5, 2012 17:08 |
|
I meant just this line (the try statement) comment.try(:user) == user || user.role?(:moderator) #what is this line doing? But I think I get what try does now, it sees if user field exists and that the object its being called on exists right?
|
# ? Apr 5, 2012 17:13 |
|
http://archives.ryandaigle.com/articles/2008/11/20/what-s-new-in-edge-rails-object-try
|
# ? Apr 5, 2012 17:38 |
|
Why aren't you looking at the API documentation first? Typing 'try' to that search box would've given you the answer in 5 seconds flat. http://api.rubyonrails.org/
|
# ? Apr 5, 2012 17:54 |
|
Smol posted:Why aren't you looking at the API documentation first? Typing 'try' to that search box would've given you the answer in 5 seconds flat. I now have it as one of my homepage tabs though.
|
# ? Apr 5, 2012 18:04 |
|
Does anyone (like pardot) know how to set BUNDLE_WITHOUT on the Cedar stack on Heroku? It doesn't seem to do anything when I follow Heroku's directions.
|
# ? Apr 5, 2012 20:45 |
|
Apparently I haven't made the effort to understand the semantics of nested vs. scoped resources enough to know whether I'm structuring my routes and controllers wrong. I'm sure it's incredibly basic, but I made some assumptions early on that made things kind of messy. When you have an association like "a blog post has many comments", it's obvious that you'd use a nested resource since comments are always accessed in the context of a post. With the case of something like "a department has many employees", the department context is optional. I wanted to have "pretty" urls, so at the time I felt I needed 2 controllers: one that's unscoped and one that's always scoped to a department. Obviously you could combine them in one controller, but I didn't want to do something like: code:
code:
This is just a simple example, but the dataset I'm working with is necessarily highly relational and there are much more complex relationships than this. After some time, I started drowning in specialized controllers whose only real difference was in what table(s) they're performing a join to (or not). So where's the middle ground between flexible, "pretty" routing with lots of specialized controllers and a single, swiss-army-controller that handles all your scoping and filtering needs? Writing this post makes me feel like I'm really bad at Rails. Thoom posted:Disregarding my brain fart about scoping rules, I still think it's dumb how poorly documented the scoping of various namespaces is in Rails. Big Nubbins fucked around with this message at 23:30 on Apr 5, 2012 |
# ? Apr 5, 2012 23:25 |
|
greasy digits posted:http://www.ruby-doc.org/docs/ (home of the official core API docs as far as I'm aware) reference many guides with detailed info on lexical scoping. I wasn't talking about Ruby's scoping rules. I was talking about incredibly obscure Rails implementation details like Rails.application.routes.url_helpers that are sometimes useful to have outside the context Rails provides them in by default.
|
# ? Apr 5, 2012 23:44 |
|
prom candy posted:Does anyone (like pardot) know how to set BUNDLE_WITHOUT on the Cedar stack on Heroku? It doesn't seem to do anything when I follow Heroku's directions. By default the slug compiler does not see your runtime environment, so it doesn't know you have that You need to set the user_env_compile flag on your app. You can do that with the newish heroku labs feature https://devcenter.heroku.com/articles/labs-user-env-compile In general we don't like user_env_compile. Your build environment should be different than your run environment, so don't expect this lab feature to stick around forever. Your running app doesn't care about BUNDLE_WITHOUT, and your slug compiler doesn't give a gently caress about your DATABASE_URL. Until that mess is all figured out, user_env_compile is the answer.
|
# ? Apr 5, 2012 23:51 |
|
Pardot posted:By default the slug compiler does not see your runtime environment, so it doesn't know you have that You need to set the user_env_compile flag on your app. You can do that with the newish heroku labs feature https://devcenter.heroku.com/articles/labs-user-env-compile Awesome, thanks. If you think of it, do you mind updating this thread when you guys have a different solution for this or if this option is going to be removed? Somehow I always manage to miss stuff like that.
|
# ? Apr 6, 2012 01:12 |
|
I think I found the "middle ground" I was seeking earlier in the form of the has_scope gem. Still, I'd like to know what "The Rails Way" is to keep that poo poo DRY. Speaking of scopes, is there a gem that evals your models to provide basic sorting, filtering, and association scopes? Hobo's Scopes module is pretty much right on the money, but without the reliance on method_missing to work the magic for you. The API I'm putting together is pretty heavy on the sorting and filtering, and it's getting to the point where the majority of my model class definition consists of scope definitions.
|
# ? Apr 6, 2012 01:18 |
|
greasy digits posted:I think I found the "middle ground" I was seeking earlier in the form of the has_scope gem. Still, I'd like to know what "The Rails Way" is to keep that poo poo DRY. I tend to move the finder into a controller method: code:
|
# ? Apr 6, 2012 02:22 |
|
BonzoESC posted:I tend to move the finder into a controller method: decent_exposure does this (and more) for you, and it's full of awesome. manero fucked around with this message at 04:33 on Apr 6, 2012 |
# ? Apr 6, 2012 04:30 |
|
I'm trying to come up with a simple ranking system for a Post model in order to display them on the front page my website by descending rank. But I also want some sort of time decay on the rank so certain posts don't stay on the front page forever. The solution i'm trying to implement is to schedule a recurring cron job with the 'whenever' gem that takes the current rank and multiplies it by a factor of Math.exp(-time_since_creation/tau) where tau is the half-life, so to speak. So my schedule.rb for whenever would be something like code:
I'm pretty new to Rails, i've only recently completed railstutorial.org.
|
# ? Apr 9, 2012 02:12 |
|
I'm not really an SQL wizard but couldn't you potentially write an SQL query that handles the sorting? Something like "ORDER BY (EXP(-time_since_creation/tau)" basically? I'm not sure how performance on that would be though. Alternately you might be able to run an update_all method to save that value to the posts themselves. code:
|
# ? Apr 9, 2012 02:50 |
|
Well the thing is that time_since_creation isn't an attribute in the Model, I have a :created_at attribute and time_since_creation = (Time.now - post.created_at) or something like that. My activerecord knowledge is pretty basic, I don't know if it's possible to write a statement that would incorporate that.
|
# ? Apr 9, 2012 03:27 |
|
You would probably have to do that operation at the database level as well. Assuming we're looking at millions of post objects I'm not certain if there's going to be a way that runs nightly updates on all of them that isn't a super expensive operation. Moving it to the order statement and caching aggressively is probably going to be your best bet, but others may have a better solution. This might be a good question for the SQL thread as well.
|
# ? Apr 9, 2012 04:03 |
|
code:
Edit: It was a pathing issue. Once I corrected the path in .bash_profile and reinstalled the pg gem it is working as expected again. What's really bothering me is the inability to play with Rails Apps Composer, since the active record recipe doesn't allow me to provide the username / password / host options. It simply tries using the default rails database.yml, which results in the script being unable to access the db. While I'm at it, how do people feel about Rails Apps Composer, or Rails Wizard? Are they a good idea to use for basic app templates? Or would you rather stick to the manual approach of setting up a new app? Oh My Science fucked around with this message at 19:02 on Apr 9, 2012 |
# ? Apr 9, 2012 08:50 |
|
Oh My Science posted:While I'm at it, how do people feel about Rails Apps Composer, or Rails Wizard? Are they a good idea to use for basic app templates? Or would you rather stick to the manual approach of setting up a new app?
|
# ? Apr 9, 2012 12:22 |
|
I use Rails Wizard all the time.
|
# ? Apr 9, 2012 16:51 |
|
k-selectride posted:My question is how to craft the update_rank method? I don't think it's possible to do that kind of thing with just a single SQL query. Is there a way to avoid loading every Post instance into memory and updating them individually? Alternatively, I would be open to another method for time-decaying of rank. I might be wrong, but I feel like this hand-baked SQL would be pretty close (I have not tested it on anything) code:
... in PostgreSQL, anyway, which has a native 'exp' function. I don't know a lot about sqlite. Sivart13 fucked around with this message at 19:28 on Apr 9, 2012 |
# ? Apr 9, 2012 19:26 |
|
Sivart13 posted:I might be wrong, but I feel like this hand-baked SQL would be pretty close (I have not tested it on anything) Thanks for the help everybody, I'll give this a shot and see how it works. If it gets too complicated I'll simply implement time based weight that gets added to votes. So I'll pick an arbitrary reference day, say 01/01/12 and calculate the change in rank from a vote as post.rank = post.days_since_ref_date * weight + 1. Where weight is an integer between 1-10 to determine how quickly I want new posts to overtake older ones. Or something like that.
|
# ? Apr 10, 2012 01:42 |
|
Your solution really should depend on how many posts you have in the database. Running a once-a-day update_all on a few hundred posts isn't a big deal, but that solution won't really scale.
|
# ? Apr 10, 2012 04:14 |
|
While the half life thing is kinda neat, does it really give you any more than select * from posts where created_at > '5 days ago'::interval order by created_at desc limit 20 ? That one is super easy, seems like it gives you roughly the same things, and you just need to make sure you have an index on created_at.
|
# ? Apr 10, 2012 04:25 |
|
I think the issue is that he wants to combine their age with a rank that's determined through other means (user votes maybe?) That was my take anyway.
|
# ? Apr 10, 2012 16:16 |
|
Not strictly a Rails question but is there any way to improve the spin-up time on free Heroku apps? Or to profile the spin-up and determine why it's slow?
|
# ? Apr 12, 2012 16:54 |
|
prom candy posted:Not strictly a Rails question but is there any way to improve the spin-up time on free Heroku apps? Or to profile the spin-up and determine why it's slow? It's probably the same reason it's slow to spin up on your machine, if you want to profile it locally.
|
# ? Apr 12, 2012 17:02 |
|
BonzoESC posted:It's probably the same reason it's slow to spin up on your machine, if you want to profile it locally. This + how big your slug is, since it has to be downloaded first.
|
# ? Apr 12, 2012 17:11 |
|
Downloaded from where to where? Is there a size that I should try to stay under? I saw on Stack Overflow that installing addons like New Relic will keep your application alive because they hit it fairly frequently. Is this considered abuse/misuse of the free service provided by Heroku?
|
# ? Apr 12, 2012 17:26 |
|
prom candy posted:Downloaded from where to where? Is there a size that I should try to stay under? Presumably from S3 to EC2. https://devcenter.heroku.com/articles/slug-size says 100mb is a hard limit, 25mb is good. Obviously, 1mb would own, but good luck.
|
# ? Apr 12, 2012 17:39 |
|
BonzoESC posted:Presumably from S3 to EC2. This. While the download speeds are extremely fast, it is still a limiting factor. prom candy posted:I saw on Stack Overflow that installing addons like New Relic will keep your application alive because they hit it fairly frequently. Is this considered abuse/misuse of the free service provided by Heroku? It is considered abuse, but more importantly it makes me sad. People who do this make it harder for us to offer a free service, and I like it that we have a free service.
|
# ? Apr 12, 2012 17:49 |
|
I'm learning metaprogramming in Ruby for a class project. One of the assigned tasks is to write a method which allows me to create a new method at runtime. I'm using class_eval to accomplish this. I'm at the point where I'm defining the new method using class_eval and I'd like to store a number literal inside the new method definition. Is there a way to dereference a variable so it gets stored as a literial?
|
# ? Apr 13, 2012 03:52 |
|
Related question to Heroku spinning down - how does this work on the Cedar stack? If I have 1 web dyno and 1 worker dyno, is it possible for that web dyno to spin down (i.e. do I need to have at least 2?)
|
# ? Apr 13, 2012 13:08 |
|
Jam2 posted:I'm learning metaprogramming in Ruby for a class project. One of the assigned tasks is to write a method which allows me to create a new method at runtime. I'm using class_eval to accomplish this. Would define_method work for what you're doing?
|
# ? Apr 13, 2012 14:29 |
|
enki42 posted:Related question to Heroku spinning down - how does this work on the Cedar stack? If I have 1 web dyno and 1 worker dyno, is it possible for that web dyno to spin down (i.e. do I need to have at least 2?) I am fairly certain it does not count workers towards spin down, and that yes, at least two dinos are needed.
|
# ? Apr 13, 2012 15:51 |
|
|
# ? May 15, 2024 10:24 |
|
Oh My Science posted:I am fairly certain it does not count workers towards spin down, and that yes, at least two dinos are needed. You're correct. I forgot that that was the case. I'm personally trying to get this changed, of course no promises that it will happen or any eta, but I think it's bad.
|
# ? Apr 14, 2012 05:17 |