|
MrSaturn posted:I've got another question What do your routes look like for the blogposts controller? It looks like you have it set up for /blogposts/:id, which would explain why /blogposts/rss would screw up (it's looking for a post with id of "rss").
|
# ¿ Nov 26, 2007 06:32 |
|
|
# ¿ Apr 25, 2024 03:26 |
|
OK, I'm trying to wrap my brain around this RESTful stuff, and I think I've got it. I was experimenting with refactoring one of my existing apps to REST, but here's the snag I run into. For my "user" controller, I have my routes set up like so: code:
|
# ¿ Dec 5, 2007 00:45 |
|
SeventySeven posted:Just a constant, nothing fancy. I used environment.rb to store a constant with my Google API key, that might work for you.
|
# ¿ Dec 6, 2007 01:14 |
|
I wonder if anyone could help me out with an issue I'm having. I've just deployed an app using restful_authentication on edge rails (2.3.0) and it works perfectly in my development environment. I deployed it to my web server in production however, and it seemed that the session was not persisting between requests. I set up some loggers inside the current_user= method in AuthenticatedSystem and I could see that the session variable was being set, but then when the app redirected to the page that needed authentication, logged_in? returned false and there was nothing in the session. I could see that it set a cookie however. I tried changing it to active_record_store, which worked, but now every few requests there's a pause of about 5 seconds before the page loads. Does this ring any bells for anyone? I can't figure it out and Google's been worthless. I can provide more details upon request. Thanks.
|
# ¿ Feb 23, 2009 22:51 |
|
Anyone know how I can dynamically get a list of the actions in a controller? From the console, I can do this:code:
code:
|
# ¿ Mar 9, 2009 21:05 |
|
skidooer posted:Call the method after your methods have been defined. i.e. Hah wow, that was way simpler than I thought. Thanks!
|
# ¿ Mar 9, 2009 21:31 |
|
Well, after getting past the above problem, I finally finished up / extracted a plugin for search engine XML Sitemaps. There's one out there already but I didn't really like how it was installed and set up, I wanted something where I could just stick a method in my controller and have it be mapped. I have no clue if this will be useful for anybody else, but here it is: http://github.com/tylercunnion/sitemap_xml/tree/master I'll gladly accept any suggestions/patches. Let me know if you find it useful!
|
# ¿ Mar 10, 2009 16:41 |
|
I'm trying to implement custom 404 pages using method_missing in my ApplicationController. This code:code:
|
# ¿ Apr 10, 2009 15:48 |
|
NotShadowStar posted:Leaving in one minute but I don't know if that will even work, since you got to method_missing through a render with a missing template (explicit or implicit) so you'll get a double render error when you get that far. I think. You probably want to look at rescue_action_in_public Cool. I just changed the code to code:
|
# ¿ Apr 10, 2009 16:10 |
|
Myrddin Emrys posted:Total newbie here, just picked up my first RoR book and tried my hand at installing it on Linux. Just as a suggestion (and someone please correct me if I'm out of date here), you should stick with ruby 1.8.7 for now. Rails is quickly being converted for use on 1.9 but it's not quite there yet.
|
# ¿ Aug 18, 2009 21:54 |
|
I've got a bit of a problem getting rails to use the right version of Ruby. My hosting provider has 1.8.6 living in /usr/bin, while I have 1.8.7 in /usr/local/bin. When I run the ruby command I get 1.8.7 but Rails has been using 1.8.6 for some reason. Any idea where this gets set or if there's an environment variable I can set up to get it looking in the right place? I'm running Thin behind Apache. ed: I get this error when I try to run script/console, if it helps: code:
Lamont Cranston fucked around with this message at 21:52 on Jan 13, 2010 |
# ¿ Jan 13, 2010 21:50 |
|
Looks like the problem came from installing 1.8.7 overtop of 1.8.6. I removed my /usr/local/lib/ruby and reinstalled and everything seems to be going well.
|
# ¿ Jan 14, 2010 06:22 |
|
Since this is more or less the Ruby thread, I'll ask this here - I'm using RSpec but I'm pretty new to it. I'm writing a web crawler and I want to set up a test to ensure that any page is only downloaded once. I have my Crawler class send an update message to my Observer class every time it downloads a page with the response and URI objects as arguments. My test looks like this: code:
code:
Lamont Cranston fucked around with this message at 23:31 on Jan 24, 2010 |
# ¿ Jan 24, 2010 23:29 |
|
Operation Atlas posted:It's hard to tell without looking at the code in your app, but I think you're passing every page url in an array each time you talk to the observer. Each time you hit a new page, the array grows and so does the list of pages passed to the observer. Because of the way RSpec does "with", as long as the page is in that array it will pass. It just passes the URI object, no array. I managed to get it to (correctly) fail when I change to: code:
|
# ¿ Jan 25, 2010 20:56 |
|
http://github.com/tylercunnion/crawler/blob/master/lib/crawler/webcrawler.rb It's not passing an array, have a look for yourselves. At any rate, I think the problem I'm having has to do with what they discuss in this ticket: https://rspec.lighthouseapp.com/projects/5645/tickets/618-exactlyntimes-incorrectly-failing-for-n-actual I stub the update method onto my observer object, because for the Observable module, observer classes must respond to update. Then, I put an expectation on top of that - and when it's finished, it removes the expectation and reverts back to the stub method - which is why it doesn't catch that the method is being called more than what I specify, but it will catch it when I put the expectation to a high number I know it won't reach. Anyway, thanks for your help. I guess I'll just have to continue to work around or else figure out something clever.
|
# ¿ Jan 27, 2010 04:46 |
|
Holy crap, how had I not heard of Heroku before? This looks amazing.
|
# ¿ Mar 27, 2010 23:53 |
|
So I get the idea that times stored in the DB are in UTC, and it's the app's responsibility to adjust for local timezones. I've set my timezone as Eastern in application.rb. My form uses a time_select. So I submit the form with a time of, say, 13:00. My understanding is that it should go into the database as 18:00 UTC (as EST is UTC-5), but it doesn't, it goes in as 13:00 UTC. Is there somewhere else I need to be compensating for this before I send it to the database? What am I doing wrong here? I had the types set in my schema as time instead of datetime. Changing that fixed it right up. Lamont Cranston fucked around with this message at 22:57 on Aug 22, 2011 |
# ¿ Aug 22, 2011 06:54 |
|
Does anyone know how I can include associated objects in a query according to a scope? I have Companies with many Jobs, but Jobs expire after a certain amount of time, so when I do Company.includes(:jobs) I want to be able to limit what it includes to just active jobs. Is there any way to do this? I already have an 'active' scope on Jobs, and I was hoping I would be able to reuse that, but I'll take anything.
|
# ¿ Oct 10, 2011 02:55 |
|
ZanderZ posted:Can anyone help me better understand methods? I'm trying to write a method for the current user that currently looks like this. First of all, a method called "current_user=" is a setter, and the body of your method is a getter. Also, "current_user", "current_user=" and "current_user?" are all different methods, that's why you're seeing a method not found error. Apart from that I don't know enough about the implementation of your authentication system to be able to say. Are you using a gem for authentication? If you are, you probably don't need to do the implementation for current_user yourself.
|
# ¿ Jan 10, 2012 17:42 |
|
Physical posted:
Base is the class' name, ActiveRecord is the module or package, :: is the namespace operator.
|
# ¿ Feb 3, 2012 22:01 |
|
Look Around You posted:That being said, if you want to really make yourself a "better" programmer, I'd recommend learning a functional language like Haskell or Lisp. They're really awesome languages in general, and functional programming is a good way to get a better grasp of recursion (especially considering that you don't really have loops at all!). It's also just good to step out of your comfort zone sometimes. A good book for learning Haskell is Learn You a Haskell for Great Good by fellow goon Bonus. Lisp has a couple good books too, notably SICP and How to Design Programs, which is sort of SICP lite. Just wanted to say thanks for this. I've always wanted to explore a functional language and I've been working through the Haskell book; fascinating stuff.
|
# ¿ Mar 3, 2012 08:11 |
|
Physical posted:Is there something that I don't know that prevents me from assigning a value to a key in a hash.each loop? Just setting v won't do it; you'll have to do data[k] = (your new v). (Though something tells me you could probably do this with inject instead. I'm not super familiar with the ins and outs but you might want to take a look.) Lamont Cranston fucked around with this message at 01:05 on Mar 28, 2012 |
# ¿ Mar 28, 2012 01:01 |
|
Strong Sauce posted:inject is essentially a reduce, how is that going to help him here? I am guessing you're referring to mapping? Well yes, but map returns an array. I was thinking he could do something like code:
|
# ¿ Mar 28, 2012 03:47 |
|
Strong Sauce posted:Ah yes I kept thinking that the object returns as an array of hashes and not a hash. Still your solution doesn't actually modify `data`, it just returns a copy such that data is still not changed. True, but that's all I was really going for anyway.
|
# ¿ Mar 28, 2012 04:53 |
|
|
# ¿ Apr 25, 2024 03:26 |
|
Thoom posted:I'm starting to get really pissed off with Rails' magic. You're trying to treat Ruby like Javascript. You're defining a new class with HTMLWithRefs and nothing outside of that is in scope, regardless of whether it's in the same file. In any case, Redcarpet cannot see the methods you've defined in the helper file. Those are in their own module (ApplicationHelper) which only gets mixed into the view. You could (I guess) import the ApplicationHelper module into your file, but then your helper method relies upon the link_to method, so you'd have to include whatever module that's in, and so on. You'd be pounding a square peg into a round hole. Better to forget about trying to shoehorn helpers where they weren't meant to go, and just write out the HTML for the link yourself in your preprocess method.
|
# ¿ Apr 5, 2012 00:30 |