|
phazer posted:UGH, I realized what it is. I looked up how to do cropped thumbnails with attachment_fu/rmagick, and I remembered I found this, which makes you rewrite the processor code: Not really an expert on attachment_fu, but as far as I know most people have moved over to Paperclip. Might be worth a look if you're having problems. goodbye attachment_fu hello paperclip
|
# ? Dec 28, 2008 15:14 |
|
|
# ? May 18, 2024 03:00 |
|
Is there a way to easily report at the bottom of the page on a development application the processing time, requests and speed of which the page loaded? I am getting tired of always looking over to my terminal window on every page request to see even just a summary of what's been happening. Also another question; I understand that the development environment runs a bit differently than in production. Now that I've got my db requests more or less optimized for the time being I'm noticing that my bottleneck seems to be loading partials, for instance I am using a commenting system and each comment is a partial with another partial in it for the rating system. When there are 25 comments being loaded on the page each one loads at a speed of between 0.7-1.7ms for the rating and 1-3ms per comment, in comparison the full amount of db requests on such a complex page load maybe 0.3ms in absolute total. Why are the partials being loaded slowly, in production are these partials just going to be in memory or something? Thanks in advance for both questions Nolgthorn fucked around with this message at 01:50 on Dec 29, 2008 |
# ? Dec 29, 2008 01:48 |
|
Nolgthorn posted:Is there a way to easily report at the bottom of the page on a development application the processing time, requests and speed of which the page loaded? I am getting tired of always looking over to my terminal window on every page request to see even just a summary of what's been happening. You might like FiveRuns Tuneup. Personally, I've tried things like this but always end up just looking at the console while optimizing. Nolgthorn posted:Also another question; I understand that the development environment runs a bit differently than in production. Now that I've got my db requests more or less optimized for the time being I'm noticing that my bottleneck seems to be loading partials, for instance I am using a commenting system and each comment is a partial with another partial in it for the rating system. When there are 25 comments being loaded on the page each one loads at a speed of between 0.7-1.7ms for the rating and 1-3ms per comment, in comparison the full amount of db requests on such a complex page load maybe 0.3ms in absolute total. Rails performs vastly different in production mode. Templates are cached, so if you make a change to them you have to restart the process. I have noticed performance problems with rendering too many partials in the past, but that's when there's hundreds. The overhead should be minor with 25. You should do yourself a favor and enable production mode from time to time during development (just point your production entries in database.yml at the development database and it should work.)
|
# ? Dec 29, 2008 01:55 |
|
Nolgthorn posted:Why are the partials being loaded slowly, in production are these partials just going to be in memory or something? Partials are just never going to be really fast. They do have very different performance characteristics in development mode though, since I believe they're manually loaded from disk and parsed every time. Try turning template loading caching on manually in your environments/development.rb to get a better idea. In production these partials should sit loaded in memory. code:
You're hitting against one of the most frustrating parts of working with rails. The trade off between performance and clean code structure.
|
# ? Dec 29, 2008 02:01 |
|
Thanks you guys for your help. I have another question that might be really simple. Is there a way I can update a column in the database on a table that contains a field named updated_on, without having the updated_on field update? In the old days it was possible to do: code:
Edit: It seems that I cannot even hack my way around it, here is my fat controller code: code:
I may need to call the column something different if I want to have more control over it I guess. Nolgthorn fucked around with this message at 12:05 on Dec 29, 2008 |
# ? Dec 29, 2008 11:48 |
|
Nolgthorn posted:I may need to call the column something different if I want to have more control over it I guess. Honestly, you're fighting against the tide of convention. I'd just call it something else (last_updated_at/on etc), add before filters to change the attribute automatically if you want to retain some of the behavior. Minor code tips based on your sample: It might be worth altering the the thread before the save call to minimize on the number of database writes, so only one save is called. code:
One more minor thing to think about is transactions. If you're saving more than one thing at a time, it's probably worth batching it in a transaction. This is a really unlikely circumstances, but what if the DB server died after the "@forum_thread.save" call, but before the "@first_post.save" call, you'd have invalid/inconsistent data. Not a big deal for threads/forums, but something to consider for other projects.
|
# ? Dec 29, 2008 14:02 |
|
Nolgthorn posted:
Oh. Gosh. Where do I start? First thing's first: Controllers should be skinny. Something is wrong if your controller has any logic that is concerning anything other than these things: Rendering, redirecting, security, requests, sessions or parameters. "Business logic" has absolutely no place in the controller. Get that stuff to the model, and I think you'll find a lot of the complexity will melt away by itself. Secondly, this stuff is so much easier to test once it is in the model. You should have comprehensive unit tests built around this stuff. That way, you KNOW it works, instead of the "test and refresh" method of "testing" your code (Where you THINK that it PROBABLY works). If it doesn't work, you know exactly what is wrong. Thirdly, fetching your @forum_thread should probably not be in a before_filter, but if it is, verify_is_owner should be called along with it. That way, by the time you get in the method body of "update" you know everything is kosher with permissions and you can just keep going. Fourthly, you should definitely be using a different attribute name than updated_on. You're not really tracking updated_on in this case, so rename the dang thing. Fifthly, use && instead of "and". They are NOT the same thing. They have different precedence. code:
I don't mean to harsh on you, but it's best that you learn these conventions as quickly as possible. It's better for you, and for anyone who might have to read your code in the future. (Also, in response to Hammertime, I never use save!. I'm not sure if it is just preference or what, but I like if->else over begin->rescue)
|
# ? Dec 29, 2008 17:01 |
|
I am being honest when I say that is some of the ugliest code I have written... sigh the Internet and posting things I will regret. The code would look a lot cleaner if 'they' at Rails core would get associated objects built all in one request, that way I could easily tuck the params[:first_post] inside of params[:forum_thread][:comment] and be done with the whole thing. I did try putting some logic in my model for this along the lines of: code:
I have since renamed the offending column like you guys have mentioned, I don't fully know what I was thinking... something seems simple and I get further along then it's no longer any good for my purposes. I am however going to maintain that && is more or less exactly the same as 'and' for me generally because I only ever use 'if' or 'unless' statements with booleans. Nolgthorn fucked around with this message at 17:32 on Dec 29, 2008 |
# ? Dec 29, 2008 17:25 |
|
Nolgthorn posted:The code would look a lot cleaner if 'they' at Rails core would get associated objects built all in one request code:
|
# ? Dec 29, 2008 17:32 |
|
Exactly, except that it would do something once it hit the .new(params) method.
|
# ? Dec 29, 2008 17:33 |
|
Nolgthorn posted:I am however going to maintain that && is more or less exactly the same as 'and' for me generally because I only ever use 'if' or 'unless' statements with booleans. In Ruby, all objects are 'True' except 'False' and nil, so it doesn't really matter. The precedence can really hurt sometimes, as it's unexpected. The 'and'/'or' versions of &&/|| have really low precedence - lower than assignment. That can get tricky... easier to just use what will behave as expected. http://phrogz.net/ProgrammingRuby/language.html#table_18.4
|
# ? Dec 29, 2008 17:35 |
|
Nolgthorn posted:Exactly, except that it would do something once it hit the .new(params) method.
|
# ? Dec 29, 2008 17:50 |
|
Is there a cleaner way of handling the output of validation errors without monkeypatching ActionView::Base.field_error_proc ? I really don't like how it just injects html in the view when I have a nice system using the flash for displaying errors. I have this code, and it's fine:code:
|
# ? Dec 30, 2008 20:29 |
|
NotShadowStar posted:Is there a cleaner way of handling the output of validation errors without monkeypatching ActionView::Base.field_error_proc ?
|
# ? Dec 30, 2008 21:06 |
|
Digging into the depths of the Rails wiki, home of abandoned and unfindable pages brings up http://wiki.rubyonrails.com/rails/pages/HowtoChangeValidationErrorDisplay So yeah, that works then. Use my notification system to display the errors and use the proc that's fired on validation fail to add a "FAIL" class to the errant fields. Awesome.
|
# ? Dec 30, 2008 22:36 |
|
I too don't like the way field_error_proc adds that horrible div around failing form elements, it's always messing up my layouts. I usually make it a point to add this at the very end of my environment.rb: code:
Edit: As a related question is there a way to reliably return error messages on the fields from an associated model, then display them or what is the best practice for this? Nolgthorn fucked around with this message at 15:20 on Dec 31, 2008 |
# ? Dec 31, 2008 14:46 |
|
Nolgthorn posted:I too don't like the way field_error_proc adds that horrible div around failing form elements, it's always messing up my layouts. Why not just use CSS to not display it as a div? If you change the div's style to have display: inline in your CSS it is basically the same thing as a span.
|
# ? Dec 31, 2008 16:46 |
|
And an unstyled div shouldn't be affecting your layout at all unless you've done something really lazy like #content div {}
|
# ? Dec 31, 2008 17:04 |
|
Usually I use paragraph tags around my form elements, then I have things on the right of it or maybe I've got a field in the middle of a sentence for some reason I dunno stuff gets messed up. True I could use display inline on the divs but why not use span though, it's nice to have the control.
|
# ? Dec 31, 2008 18:14 |
|
atastypie posted:And an unstyled div shouldn't be affecting your layout at all unless you've done something really lazy like #content div {} It can gently caress stuff up since a div is a block element and spans are inline. You either have to give it the inline property like evil trout said, or I actually just saw a post about it last saturday that brought this ticket and patch to my attention.
|
# ? Jan 1, 2009 12:29 |
|
So next up on the list is I'm writing a model for handling experiment data. Experiments are always done on plates. Plates, in my context, are generally a 2d array that holds stuff. In a separate project I wrote a basic Plate class that's pretty much a 2d array with pretty accessors with other helper stuff, and specialized Plates for their own experiment are subclasses and add their own stuff. Since I want to store pretty much everything in the DB as possible, I want to store all experiment data in the database with models. Problem 1) The table is going to get large by MySQL standards. I've been considering a design of each row of the database is 1 element in the 2d array, identified by columns in the table that correlate to the position and id # of the experiment plate. Right off the bat I'd be importing about 15,000 experiments, and each experiment can have up to 384 elements (more like an average of ~ 330) so bam that's ~4.95 million rows and probably grow another 1-2 million a year. That's just for one type of experiment, there will be others that will add other millions of rows in this manner to other tables. Other information systems that do something similar to what I'm doing have the same strategy, but they use higher end databases and I understand MySQL might not like this. The other thing is since there will be several models that are similar but have different properties for different types of experiments or similar data I feel like I should be looking into writing an acts_as, but I don't know the first thing about that. NotShadowStar fucked around with this message at 19:59 on Jan 2, 2009 |
# ? Jan 2, 2009 19:56 |
|
NotShadowStar posted:So next up on the list is I'm writing a model for handling experiment data. Experiments are always done on plates. Plates, in my context, are generally a 2d array that holds stuff. In a separate project I wrote a basic Plate class that's pretty much a 2d array with pretty accessors with other helper stuff, and specialized Plates for their own experiment are subclasses and add their own stuff. Firstly, 1 row per experiment is probably the right way to go (provided you don't need to pull experiments based on their results). One row per element is an extremely wasteful approach. Secondly, if you've got various different experiment types with differing data requirements your have a couple of choices. The first is to have one table per experiment type. The second is to use RoR's single table inheritence and base multiple models around it, I'm not overly familiar with this approach, but it should be fine given you only have 15,000ish experiments. Splitting the experiment data off into it's own table and giving it a polymorphic association back to the experiment tables is also an option. As to how you store the data itself, I'd need a bit more information on what each element details, but storing it into a text column with a small bit of encoding is my current gut feeling. MySQL really isn't friendly to multidimensional data. NotShadowStar posted:The other thing is since there will be several models that are similar but have different properties for different types of experiments or similar data I feel like I should be looking into writing an acts_as, but I don't know the first thing about that. As an intermediary to plugin writing (as this can be a slightly tricky endeavor on your first go), perhaps just use a mixin for common functionality and include it in each of your experiment models. Hammertime fucked around with this message at 03:54 on Jan 3, 2009 |
# ? Jan 3, 2009 03:52 |
Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc...
|
|
# ? Jan 10, 2009 13:46 |
|
Panic! at the Fist Jab posted:Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc... No not really, I am really looking forward to Rails 3 they promise to merge Merb and hopefully we get nice little things like recursive database manipulation.
|
# ? Jan 10, 2009 13:48 |
|
Panic! at the Fist Jab posted:Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc...
|
# ? Jan 10, 2009 18:22 |
|
nebby posted:I have yet to bite the bullet, but running multithreaded Rails on JRuby is going to be a big win for us theoretically. (We're running JRuby now, but on Rails 2.1 with Ruby Runtime pooling.) Faster server restarts and dramatically reduced memory, since it does not have to cache the ASTs for all the gems N times. We evaluated JRuby at work for a good while but eventually scrapped it. This was a while back and I assume JRuby has matured. Can you describe your deployement method with JRuby?
|
# ? Jan 10, 2009 18:36 |
|
Panic! at the Fist Jab posted:Is anyone using edge Rails and the latest featureset that Rails provides consistently? I stopped using Rails about a year ago and focused on microframeworks like Sinatra, and I'm wondering if there's anything really amazing that I'm missing that the switch to Rails may be worth it again. Any awesome plugins, etc...
|
# ? Jan 11, 2009 17:37 |
|
What do you guys like better: braid or git submodules? Both have been frustrating.
|
# ? Jan 11, 2009 23:34 |
|
Pardot posted:What do you guys like better: braid or git submodules? Both have been frustrating. I gave up on submodules. I just commit everything straight into the repo. You suffer from a dirtier history, but it is so much easier to deal with and deploy. I might try it again though. The primary reason why i gave up on it was because I was still using git-svn (for Trac), and submodules don't work at all with git-svn. I've never used Braid... How is it different from Piston?
|
# ? Jan 12, 2009 17:27 |
|
Ghotli posted:We evaluated JRuby at work for a good while but eventually scrapped it. This was a while back and I assume JRuby has matured. Can you describe your deployement method with JRuby? Overall, my biggest complaint with JRuby is startup time -- it sucks. I've talked with the JRuby guys about ways to improve this but I don't think its very high on the priority list. The main problem is JRuby's parser and lexer is pretty slow, and so parsing and lexing all the gems at startup time takes a significant amount of work. Multithreaded Rails will reduce this burden on the server since it only has to do this once, instead of N times for each Ruby runtime, but on the client you still end up having to wait 20-30 seconds for a script/console Other than that, JRuby is rock solid, we have been using it for a few months now and being able to integrate with Java code we already had has been a huge help.
|
# ? Jan 13, 2009 17:49 |
|
Okay I redefined my original problem and came up with a much better solution. Now I'm wondering if some AR gurus can help out with this. I have this first-stab design (in migration format) code:
If I just needed one then that's easy, SdsExperiment belongs_to :stock_plate and StockPlate has_many :sds_experiments. However, I need up to 4 stock plates, and the order of them is important (I need to know what stock plate 1 is). Essentially I want to say something like belongs_to :stock_plate, :using_instance_method => :stock_plate_1. So in the end I can do something like Experiment.find(1).sds_experiment[1].stock_plate_1.clownfarts If this makes any sense at all...
|
# ? Jan 16, 2009 02:46 |
|
nebby posted:jruby... I assume you're using glassfish v2 since v3 isn't stable yet. At work we have a few rails applications that we need deployed at the same time. When we were looking into glassfish I remember v2 not being able to host more than one rails app at a time. Do you have any idea if this is true or not? We also had a whole lot of trouble getting warbler to work correctly. Obviously it's stable enough now for you to use in production. Do you have capistrano create the war file on the production server? If so could you show us the code for how you did that. Also, what is your rationale for warming up the production servers with curl. Is this so you can keep the rails environment in memory?
|
# ? Jan 16, 2009 03:25 |
|
Since nobody cares I'll just put this up anyway. I solved the problem of one model inheriting from another multiple times while keeping track numeric associations like thiscode:
|
# ? Jan 18, 2009 08:30 |
|
Have you considered creating your join model with an integer :position column? Seems like that might scale a little bit better than explicitly creating column_[1,2,3,4] columns.code:
|
# ? Jan 18, 2009 14:20 |
|
erp, nevermind.
dustgun fucked around with this message at 01:28 on Jan 24, 2009 |
# ? Jan 24, 2009 00:25 |
|
Ghotli posted:I assume you're using glassfish v2 since v3 isn't stable yet. At work we have a few rails applications that we need deployed at the same time. When we were looking into glassfish I remember v2 not being able to host more than one rails app at a time. Do you have any idea if this is true or not? 1) Stop domain 2) Warble 3) Start domain 4) Deploy 5) Stop domain 6) Start domain 7) Curl everything until the URLs come back instantly We curl because basically glassfish has a ruby runtime pool (8 right now for us on EC2) and so there is a very large startup time penalty since JRuby has to lex, parse, and interpret all of the gems 8 times over (and stick the AST in RAM ). Curl'ing basically warms all these things up.
|
# ? Jan 24, 2009 08:56 |
|
hey so i'm just starting out with ror and i've gone through a couple of tutorials, but i find that i learn the best when i just try to make something i think up. anyway so i'm making a site so people could post show listings. anyway i have a question concerning ajax auto-completion. this is code from my create show page. it displays all the current bands added and adds a textfield with a button so people can add more bands. code:
code:
|
# ? Jan 28, 2009 21:24 |
|
Possym posted:what i want is to make each textfield have an autocomplete based on whatever is in the band table. i tried using this scriptaculos auto complete, but i get this error: You probably need http://github.com/rails/auto_complete/tree/master since auto_complete stuff has been moved out of core.
|
# ? Jan 28, 2009 23:36 |
|
I'm considering learning and writing a RoR program(s) basically for the hell of it, to learn it. I have a need for a web application that is database dependent (Oracle 10g). If I do not go with RoR there is no way I'd even consider PHP, I'd use Java, JSP, Javascript, etc. So, given my background and disapproval of PHP, does this sound like a wise use of my time? I'm curious just so I can put another skill under my belt, but that's probably the wrong reason to get into this. Also, can RoR scripts be runnable from a command line if I had such a use? Can it communicate with COM objects?
|
# ? Jan 30, 2009 14:58 |
|
|
# ? May 18, 2024 03:00 |
|
mister_gosh posted:I'm considering learning and writing a RoR program(s) basically for the hell of it, to learn it. I have a need for a web application that is database dependent (Oracle 10g). If I do not go with RoR there is no way I'd even consider PHP, I'd use Java, JSP, Javascript, etc. I think that's the *right* reason to do it, at least the fact that you have a need for a web application. That's basically how I learned Ruby and Rails. I came from a Java/Spring/Hibernate/J2EE background, and I was astounded at how quickly I could build a good web application using Rails. There are a number of scripts available to you in the 'scripts' directory in a default rails project root. One of which is called 'runner'. You might use it like this: code:
|
# ? Jan 30, 2009 15:04 |