|
Cocoa Crispies posted:It's also how Object#BigDecimal() works, strangely: who put PHP in my Ruby?? quote:initial: code:
|
# ? Sep 2, 2012 05:03 |
|
|
# ? Jun 3, 2024 22:12 |
|
I hacked together a class method to search for models by matching query tokens to substrings of attributes in my model. Is there any way to rewrite this in a way that would permit me to chain scopes on it? I am running into issues trying to tack on will_paginate.Ruby code:
|
# ? Sep 3, 2012 02:59 |
|
Why not use your database's searching features rather than making Ruby do it? That code is going to get awfully slow once your database fills up as as soon as you run guests.select! it's going to "SELECT * FROM guests" in the background. If you're using postgres pg_search (https://github.com/Casecommons/pg_search) is pretty good, and there are a lot of full text search gems/plugins for MySQL too (ferret, SOLR). At this point I think even using LIKE would be preferable to how you've got it set up.
|
# ? Sep 3, 2012 17:21 |
|
if anyone's interested in seeing what a very barebones Rack middleware gem looks like, I wrote one last night: https://rubygems.org/gems/rack-city (github: http://github.com/tomjakubowski/rack-city)
|
# ? Sep 4, 2012 04:23 |
|
Hi folks! I'm updating Redmine from 1.3.1 to 2.0.3, which involves updating rails 2 to rails 3, among other things. My current installation is actually a bitnami redmine stack on windows. It installed fine and has been working great for a year now. I think my options are (A) try to update rails and rake and all the other things that redmine 2.0.3 requires, and then work my way through the redmine upgrade guide. (B) store a mysqldump of the database, uninstall the bitnami redmine 1.3.1 stack, install the bitnami redmine 2.0.3 stack (which will have all the necessary dependencies), restore the database, and run "rake db:migrate RAILS_ENV=production" to update the 1.3.1 database to the 2.0.3 schema. Which one seems like less of a headache?
|
# ? Sep 7, 2012 15:24 |
epalm posted:Hi folks! I'm updating Redmine from 1.3.1 to 2.0.3, which involves updating rails 2 to rails 3, among other things. They both sound like a PITA, but I'd probably just follow the guide. Are you using Pik? It might not apply in this situation but I found it helpful when I developed on Windows. (https://github.com/vertiginous/pik)
|
|
# ? Sep 7, 2012 16:48 |
|
I get this error when running resque-web. I've tried rebooting, reinstalling resque and vegas and recompiling ruby. This started happening after I ran out of hard drive space while a resque job was writing to a file. I made some free space but resque-web hasn't started since. I've tried on ruby 1.9.2 and 1.9.3 and the same error happens:quote:dan@ubuntu:~$ resque-web
|
# ? Sep 11, 2012 13:52 |
|
Is there such a file or directory?
|
# ? Sep 11, 2012 14:21 |
|
prom candy posted:Is there such a file or directory? Cock Democracy fucked around with this message at 15:55 on Sep 11, 2012 |
# ? Sep 11, 2012 15:51 |
|
What's going on in /home/dan/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open-uri.rb at line 35?
|
# ? Sep 11, 2012 15:54 |
|
prom candy posted:What's going on in /home/dan/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open-uri.rb at line 35? Here it is. Line 35 is commented: code:
|
# ? Sep 11, 2012 15:57 |
|
Huh... I know that open-uri will try to open local files under certain circumstances, but I'm not sure in this situation why it would be doing that.
|
# ? Sep 11, 2012 16:02 |
|
Delete the resque_web.url file. It's likely empty right now, as it couldn't write to it when the disk is full. E: It's likely in ~/.vegas/resque_web.url E2: And if that's not it, why don't you fire up a debugger and see what it is trying to open? It's a lot easier to debug errors like this by simply checking yourself what the code is actually doing. Smol fucked around with this message at 16:23 on Sep 11, 2012 |
# ? Sep 11, 2012 16:12 |
|
Smol posted:Delete the resque_web.url file. It's likely empty right now, as it couldn't write to it when the disk is full.
|
# ? Sep 11, 2012 16:23 |
|
Cock Democracy posted:That worked. Thanks a ton! I had been trying to figure that out since last week. I was about to break down and configure a new VM for it. Come on man, since last week? You shouldn't be afraid to read library code (in fact, I'd argue that one should read the code for the libraries that they're using, if possible). Let me show you what what I did to solve your problem so the next time a similar problem comes up, you can fix it yourself. In the stacktrace you can see that open was called from some method called port_open?. Let's open up lib/vegas/runner.rb and see what it looks like. Ruby code:
Ruby code:
Ruby code:
Ruby code:
Ruby code:
So I guess what I'm trying to say is that, with just a bit of courage, problems like this are very easy to solve by yourself. Don't be afraid to read code that you haven't written yourself. Smol fucked around with this message at 10:34 on Sep 17, 2012 |
# ? Sep 11, 2012 17:01 |
|
Thanks Smol. I'll keep that in mind and will dig a little deeper next time.
|
# ? Sep 13, 2012 17:51 |
|
I want to get into this Rails thing, but this is so daunting. Should I just master Ruby first before attempting Rails, or keep on with trying Ruby and RoR at the same time?
|
# ? Sep 16, 2012 00:13 |
|
I started learning rails & ruby at the same time, so it's possible. A few months back I decided to focus more so on ruby in order to better understand what rails does, and I have to say it makes my life easier. I signed up for the pragmatic online ruby course, which proved to be a decent resource. At this point I would like to dig deeper, not sure where I should look though.
|
# ? Sep 16, 2012 00:38 |
|
You might want to check out Sinatra first and build something simple to get your feet wet.
|
# ? Sep 16, 2012 03:33 |
|
Ruby and Rails at the same time is how I learned. It was confusing at first but I think the benefit of being able to build useful software really quickly outweighed the drawback of not being clear on what was Ruby and what was Rails.
|
# ? Sep 16, 2012 04:05 |
|
I'm having a database issue. At some point, I introduced a migration to add a full_name string to my user model. This was applied to the production database and now the column exists in the app_production db. Around this time, I had some issues with migrations and had to delete the migration that introduced this column. So, now I have a column with no migration on record that explains how it got there. User.full_name is kind of like an orphan in that way. I just set up a capistrano task to backup my production db and apply it to my local development environment. Now, for some reason my schema on my local machine shows that the full_name column no longer exists in my schema. git is prompting me to check-in this change. I don't want to. However, I do want to re-introduce the migration that added full_name so that my local and production environments are back in-sync. However, if I were to create a new migration to create full_name, production would ERROR saying that the column already exists. How should I resolve this? Is it sufficient to create a conditional migration that adds the column so long as it doesn't exist, and to include a down method that drops the column only if it does? edit/update: I added conditional migrations to remove the bunk columns and tables and all is well. Jam2 fucked around with this message at 06:58 on Sep 19, 2012 |
# ? Sep 19, 2012 05:47 |
|
Steal the schema.rb from production and db:schema:load that into development. (If for some reason production's schema.rb is missing the column, run a db:schema:dump in production first.) The existing migrations are then unnecessary, the DB will be up to date with production regardless of what migrations are available, and loading the schema is the correct way to bring up a new instance of the database anyway. In the future, don't delete migrations, especially if they've been run in production.
|
# ? Sep 19, 2012 07:03 |
|
I'd add on one thing to what Molten Llama said. Once you have your schema.rb in development set, delete all of your migrations, and create a single new migration with the contents of your schema.rb file in the up method. He's right that you shouldn't really need the past migrations going forward, but if you're going to leave your migration folder in a state where it technically can't bring a database up to it's current state, you're asking for trouble - what if a developer does try to create a new DB through migrations and something is left in a broken state (and worse yet, you guys are ping-ponging on schema files since he's missing an important column)? Alternatively, if you don't want to lose your migrations folder, you could have just gone back into git and found the old migration and recreated it - so long as the identifier at the beginning matches, Rails won't re-run the migration (or, if you need to get REALLY fiddly with what you want torun, you can manipulate the contents of the schema_migrations table in your DB)
|
# ? Sep 19, 2012 12:00 |
|
Jam2 posted:I'm having a database issue. See what entry in schema_migrations in production doesn't have a corresponding migration file, and put the new column in a file with that name.
|
# ? Sep 19, 2012 16:44 |
|
e: Nevermind. It does work. I have many other issues but this isn't one. leaving it here anyway Working on a gem for Google Adwords where their API requires me to use different services and send requests with different field types some required some not etc. So, I started trying to build a structure for the files wherein I could define said fields. code:
Where :f means you can filter by it, :r means it is required, :s means you can search by it and on and on. These get parsed and stored as a big list of different class variables for different purposes later when actions are taken on the class such as filtering or searching. So anyway that's what I've been doing. Running into a snag passing variables between modules in this gem, one of them seems to completely disappear after defining it. code:
code:
code:
I am asking in case this is a ruby thing that people know about. {}? Nolgthorn fucked around with this message at 02:44 on Sep 20, 2012 |
# ? Sep 20, 2012 01:45 |
|
Thanks for the tips, guys. Production and development are back in sync.
|
# ? Sep 21, 2012 13:07 |
|
We are currently evaluating Rails for a few new projects and while I'm finding answers for most of the detractor's questions, there is something I can't seem to get a good answer for: How to share layouts between multiple applications? Currently we are using PHP for most of our applications and over a decade of business, a system has emerged so that over 100 applications all use only 5-6 different Smarty templates as what Rails would call "layouts" (of course each application has dozens of Smarty templates, but they are used much more like views) To pull this off we have some code that does a database lookup based on an ID each application has, and it then just sets the Smarty dir to whatever dir the database returns (I'm summarizing this, it does more, but this isn't a PHP subreddit). All of the developers use the same dev server so we don't have to worry about keeping template repositories up to date or having a bunch of different paths setup (I have issues with this as well, but that's another post) This system works great if a small layout bug is spotted because it can be fixed on all of the applications at once. It can be a problem because anytime we want to do something new with layouts, it turns into a huge headache because we have to address every possible case for every possible issue because it maybe used on over 100 applications. In the research I've done, what little I've found on doing this tells me to use a plugin to pull this off. I wrote a very basic plugin (I have no idea what I'm doing. Most of it was just Google, then copy-and-paste) that uses a Railtie to change the layout dir based on some variable. This seems to work in the couple of "Hello World" apps I've tested it with, but it would require devs to have a layout repository checked out, and I'm sure each dev would have it pointing at a different location, so each time a dev checked out the project, they would have to change the path again etc. Furthermore, if there is an update to the plugin, each application would need to update the plugin version, etc. (I only have a rudimentary understanding of plugins, so I'm probably wrong on how this works) Another way is symlinks, but that just seems like it would cause all sorts of problems, especially when moving between servers/environments. Some people said use git to import layouts. I see issues with that as well (no auto update when a layout is changed) This leads me to believe that perhaps sharing layouts between multiple applications is not a good practice, and although it maybe a monumental pain in the neck, going through application by application changing a layout issue might end up being the better way to go in the long run (It would certainly make arbitrary app specific changes easier) So finally, here are my 2 questions: 1) How can I share layouts amongst applications in a way so that if a layout is updated, all applications that use that layout are updated? 2) Is doing this even a good practice? If not, what are the alternatives? Let me know if this is long enough to deserve its own thread. TL;DR - Just read the bold. Lagg fucked around with this message at 17:21 on Oct 9, 2012 |
# ? Oct 9, 2012 17:18 |
|
You could share the layout files in a gem. You would still need to bundle update the gem + restart each application when the layout is modified, but that could be automated. You could also set up git hooks to update the servers automatically when the layouts repo is modified. First time you get a conflict because a dev modified a local layout you're going to be pretty annoyed, though.
|
# ? Oct 9, 2012 17:59 |
|
atastypie posted:You could share the layout files in a gem. You would still need to bundle update the gem + restart each application when the layout is modified, but that could be automated. Could you elborate on this a bit? Would I just need a folder called "layouts" inside of a plugin and then....magic happens? How would you personally do this? Would I want to make a different gem for each version of the layout we would use? Could you give details about application restart when changes are made? "Something...Something...Capistrano...MAGIC" right? I'm barely past the "15 minute blog" stage of Rails. atastypie posted:"Git stuff" I want that to work, but I foresee the same issue you listed,and more. Thanks for the quick reply.
|
# ? Oct 9, 2012 19:23 |
|
My dudes, recommend me a good, lightweight blogging platform I can integrate with an existing app. I tried out Toto, but it bugs me that it functions as a separate app and doesn't share my existing templates.
|
# ? Oct 9, 2012 19:46 |
|
It'll probably be faster to roll your own than try to find something that fits your needs and integrates nicely with an existing app.
|
# ? Oct 9, 2012 20:02 |
So, what's the best approach to enhancing gem-based ActiveRecord extension classes? Specifically I want to add a few class methods to the audited gem. Suppose I have a "Searchable" module with some helpful class methods that I've successfully integrated into some other ActiveRecord models using ActiveSupport::Concern. It looks kind of like this: Ruby code:
Ruby code:
|
|
# ? Oct 9, 2012 20:30 |
|
The app I'm working on has somehow gotten itself into a bizarre state. I created a migration to get rid of two now defunct columns:Ruby code:
code:
code:
It's almost as if rake is using a weird cached version of the model, and not the actual one. Any thoughts?
|
# ? Oct 16, 2012 16:53 |
|
If you're dropping the entire database to reseed it, why not just load the database from schema?code:
|
# ? Oct 16, 2012 17:36 |
|
The Journey Fraternity posted:If you're dropping the entire database to reseed it, why not just load the database from schema? Yeah, fair point. I'm new to this team, and that's what they all do as a matter of course. Anyway, a guy on our team found the solution to this: FactoryGirl needs to be reloaded: Ruby code:
|
# ? Oct 16, 2012 17:39 |
That's not so bad. I'm on a team that writes migrations that look likeRuby code:
|
|
# ? Oct 16, 2012 21:16 |
|
A MIRACLE posted:That's not so bad. I'm on a team that writes migrations that look like Notwithstanding that that should be a database 'seed' rather than a migration, don't use models in migrations. Like that, at least. http://gem-session.com/2010/03/how-to-use-models-in-your-migrations-without-killing-kittens http://complicated-simplicity.com/2010/05/using-models-in-rails-migrations/ Edit: Also, kill yourself. Then quit.
|
# ? Oct 16, 2012 21:41 |
|
Okay, I've got to know: Is password_confirmation a table column or just innocently satisfying a validation? Because in my head it's a table column, and I will be mortified/thrilled if it really is.
|
# ? Oct 17, 2012 00:47 |
|
Molten Llama posted:Okay, I've got to know: Is password_confirmation a table column or just innocently satisfying a validation? Assuming you are referring to the field created by validatds_confirmation_of :password, it is just an attr_accessor: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations/confirmation.rb#L14
|
# ? Oct 17, 2012 01:26 |
|
|
# ? Jun 3, 2024 22:12 |
It's what happens when you decide to outsource development to a team of Eastern Europeans who don't speak English (our image gallery is spelled "Galery.rb") or care about things like unit test coverage, standards or best practices, and think it's okay to write 500 character SQL queries on a single LOC. This is for a fairly prominent "daily deals" type site by the way, and the codebase is responsible for processing upwards of 200k in sales / day. I was brought on last month because the higher-ups were all "oh poo poo we don't have any developers stateside." I'm basically the SQL monkey / put out fires ops guy right now but I'm pushing for a refactor / unit test project before any new features are added. We'll see. At least the pay is good for my area.
|
|
# ? Oct 17, 2012 15:34 |