|
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 |
|
|
# ? May 29, 2024 16:56 |
|
Not necessarily a Rails question, but more of a Ruby / Module question. I recently wrote a module to try and wrap up some functionality that was duplicated across parts of our application. In doing so, I developed the module in isolation, creating public API methods along with private methods to help with the heavy lifting. Once I mixed in the module into my controller, I found that a method that my controller defined was always taking precedence of the same named method in the module that was being mixed in. This makes sense given the nature of Ruby method dispatching. It starts at the receiver's class and proceeds up the Class/Module hierarchy, finding the first method that matches the name. Of course, it would find the method defined in the object's Class before it found the method in the mixed-in Module. This made me really think twice about abstracting out functionality into Modules. I'd really love to have a way to have Ruby dispatch method calls first to the type from whence the method came instead of starting over with the normal dispatch routines coming from the object class itself. This gist gives an example of what I'm talking about. #hello invokes the Person implementation of #saying rather than the Greeter method of #saying. #hello_two bypasses this through clunky method binding to execute the Module method rather than the original Class method. Am I using Modules incorrectly here?
|
# ? Feb 24, 2009 00:40 |
|
Hop Pocket posted:I found that a method that my controller defined was always taking precedence of the same named method in the module that was being mixed in If you really wanted the module stuff to win, you can put the include at the end of the class. That's weird though, and probably misleading since people will expect the stuff in the class to win. I'm not really understanding why if you didn't want the method to run you don't just delete it?
|
# ? Feb 24, 2009 01:58 |
|
Hop Pocket posted:Not necessarily a Rails question, but more of a Ruby / Module question. I recently wrote a module to try and wrap up some functionality that was duplicated across parts of our application. In doing so, I developed the module in isolation, creating public API methods along with private methods to help with the heavy lifting. Use a nested module, and only include the top module. This is what you do when you write plugins to ensure no name collisions http://wiki.rubyonrails.org/rails/pages/HowToWriteAnActsAsFoxPlugin code:
|
# ? Feb 24, 2009 02:07 |
|
NotShadowStar posted:Use a nested module, and only include the top module. This is what you do when you write plugins to ensure no name collisions This works, but my situation is a little different. I want to mix in instance methods on a controller, as in this case I want to be able to access the params and other methods/instance_variables from within my module code as if I were in the controller. So in that case, I'd need to simply include the Module and from there call module code. I agree, though, that having in this case Clownfarts::Beafsteak as the receiver of #duck_fuck solves this problem, but I'm really looking to have the receiver of my module methods be an instance of ActionController::Base.
|
# ? Feb 24, 2009 05:04 |
|
Pardot posted:I'm not really understanding why if you didn't want the method to run you don't just delete it? That's a very good question. I have inherited some code that I am trying to refactor, and part of what I'm doing right now is to break out some code into modules to try and get my class size down. My namespace collision is in an area of the code that I'm not even working on and so I was hoping to find a way to avoid colliding with it during this refactoring.
|
# ? Feb 24, 2009 05:06 |
|
Oh great, no more capistrano? I hope the community picks up development. There's a decent flamewar going on over at Hacker News about it. Jamis Buck posted:However, please know that I am not available for questions about the code, or for advice on how to implement changes. I’m trying to cut as cleanly as I can. Any emails I get asking about the code will likely be ignored. I’m not trying to be rude; I’m just setting expectations. Dropped like a ton of bricks. Capistrano is useful and all but gosh way to abandon. "Let the community decide" sounds awfully a lot like "Let the market decide"
|
# ? Feb 26, 2009 15:42 |
|
manero posted:Oh great, no more capistrano? I think someone will most definitely pick it up. There are too many people using it (not even just in the Rails community) for it to die, really. I think Jamis handled this poorly. He should have asked for help a lot earlier, and he could have switched to a "project manager" kind of role a long time ago, kind of like DHH with Rails. For whatever reason, Capistrano was always viewed as "his" project, and bug reports, patches, etc always went through him. That's why he got burnt out, and I think that burn out was completely avoidable. That said, maybe Capistrano should die. It is pretty much a reimplementation of Rake, only less awesome. Maybe this will get people to consider alternatives like Vlad more seriously. There's no reason for a deployment solution to not use Rake. Jamis is a great developer, but his projects are always way too grandiose.
|
# ? Feb 26, 2009 18:37 |
|
Operation Atlas posted:I think Jamis handled this poorly. He should have asked for help a lot earlier, and he could have switched to a "project manager" kind of role a long time ago, kind of like DHH with Rails. For whatever reason, Capistrano was always viewed as "his" project, and bug reports, patches, etc always went through him. That's why he got burnt out, and I think that burn out was completely avoidable. Yeah, and this comment of his is telling: Jamis posted:@Nic, no, there are no other core contributors. I tried once to create something like that, but no one else seemed to have the “passion” or “vision”. Lots of people submitting patches (many of them quite good!), but no one demonstrating a real, general desire to dig into the internals. That’s kind of why I left it like I did—there really wasn’t any heir-apparent that the keys could be left to. Now, some open-source projects are going to be lucky and get matched up with someone who wants to spend ten hours per week maintaining the drat thing because what the project does just so interesting to that person. But for the most part that's just not how poo poo works. You can't run a big project like that with just one person, and you can't transition off a project by finding another dictator and dumping it in her lap. If it's big enough that you're getting burned out, you need to change the workflow — pick the part that you like doing most and get other people to help out with the rest. In other words, if I need to hire a nanny, I'm not going to look for someone who's going to love my kid as much as I do; I'm going to look for someone who knows CPR and can make sandwiches.
|
# ? Mar 1, 2009 01:12 |
|
That was just the problem with Capistrano, it WAS NOT A BIG PROJECT it was made big by the guy writing it when really all it had to be was really simple. I'm glad it's gone, I hope it never gets worked on again and I hope myself or someone else finally gets off their rear end and makes something good, like that "The Destroyer" thing which was posted. I hate Capistrano, through no personal or "emotional" response to the person who was building it, I just think that it is not useful and only gets used because people pile behind things regardless.
|
# ? Mar 1, 2009 11:31 |
|
Nolgthorn posted:I hate Capistrano, through no personal or "emotional" response to the person who was building it, I just think that it is not useful and only gets used because people pile behind things regardless. It sure solved a lot of problems for me on a big PHP project that needed a drop-in deployment tool. Maybe rake could've done the job as well, but cap was much more approachable and focused. I'm sure something will replace it but for all the projects using it now it's going to make for a lot of unnecessary, redone work just to move to something maintained.
|
# ? Mar 3, 2009 18:27 |
|
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 |
|
Lamont Cranston posted:Anyone know how I can dynamically get a list of the actions in a controller? code:
|
# ? Mar 9, 2009 21:24 |
|
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 |
|
Question; but good lord, let me try my best to explain it. I have a users table and a conversations table. I've constructed a conversation_users table to keep track of the last time a user visited a given conversation and some assorted other info that relates the two. What I want to do is eagerly load the information in this table depending on both which user is logged in and which conversations are currently being viewed. Right now my models simplified look like this: code:
What I'd ultimately like to do is add something like this to the Conversation model: code:
|
# ? Mar 12, 2009 12:23 |
|
Nolgthorn posted:What I want to do is eagerly load the information in this table depending on both which user is logged in and which conversations are currently being viewed. Right now my models simplified look like this: If I'm understanding you correctly, I think this will work: (Example for Conversations#Show action) code:
If what you want is this stuff to be automatically loaded in the model, I think you're looking in the wrong place.
|
# ? Mar 12, 2009 15:41 |
|
I have moved things to the controller like you suggest and added an extra method to the model. Thank you for your help, I'm concerned though it will start to get a lot messier as the project advances forward. Here's what I've done: code:
Something tells me I'm not doing this the rails way and I'd like to, unless this is the rails way and I'm just confusing myself. Nolgthorn fucked around with this message at 23:00 on Mar 12, 2009 |
# ? Mar 12, 2009 22:47 |
|
Nolgthorn posted:Something tells me I'm not doing this the rails way and I'd like to, unless this is the rails way and I'm just confusing myself. Well, the "Rails Way" is has_and_belongs_to_many, but you can't use that because (if I read correctly) you have extra attributes you need to keep track of. I really can't tell what you're trying to do, but you're doing it wrong. You're overthinking it. This is really quite a simple thing. code:
|
# ? Mar 12, 2009 23:11 |
|
that is what im doing. The problem is i want to eagerly load the table for items on the index, which isn't really a problem... just a concern that it's not the best way to do it. Thats all, and Im obviously doing something that isnt common after all so no worries.
|
# ? Mar 12, 2009 23:49 |
|
Operation Atlas posted:Well, the "Rails Way" is has_and_belongs_to_many, but you can't use that because (if I read correctly) you have extra attributes you need to keep track of. code:
code:
code:
skidooer fucked around with this message at 05:43 on Mar 13, 2009 |
# ? Mar 13, 2009 05:28 |
|
skidooer posted:The "Rails Way" would be to use has_many :through, which is essentially what he is doing, save actually defining the through association. If I'm understanding his models correctly, you couldn't really use has_many :through in this situation. I think what is going on is that a user can "own" a conversation (they started it, presumably), and that each conversation has an owner (what user started it). If this is not the case, then things change drastically. However, I have been working off of this assumption Nolgthorn posted:that is what im doing. I think in order to eagerly load your ConversationUser, you'd have to do this in your controller: If you want to know about only the currently logged in user: code:
code:
|
# ? Mar 13, 2009 20:12 |
|
Operation Atlas posted:If I'm understanding his models correctly, you couldn't really use has_many :through in this situation. I think what is going on is that a user can "own" a conversation (they started it, presumably), and that each conversation has an owner (what user started it). If this is not the case, then things change drastically. However, I have been working off of this assumption code:
|
# ? Mar 13, 2009 20:52 |
|
It isn't the owner... I think we're falling way off base here of what I've been trying to do, though skidooer's initial suggestion was good. Remember that the conversation_users table is there to keep track of the last time a user visited a given conversation and some assorted other info that relates the two. But I guess what I didn't clarify was that a record gets added or updated on this table once every time any user visits a conversation. There is one conversation_user record for each pairing of a conversation and a user, where the user has visited the conversation. The solution I am using based on Operation Atlas' first suggestion works, but I was aware that Active Record was capable of searching based on two indexes because I know of has_many through and I know of has_and_belongs_to_many... That's all I really wanted was to pair up the current user and a list of conversation objects then be able to eagerly load the conversation_user data for each conversation where available.
|
# ? Mar 14, 2009 00:27 |
|
Nolgthorn posted:Remember that the conversation_users table is there to keep track of the last time a user visited a given conversation and some assorted other info that relates the two In this case, you really should make it a join model like skidooer suggested. Espically since you're saying that there'll be other assorted info. Instead of ConversationUser, call it something like ConversationViewings. When a user views a conversation you can make a new one, and then keep track of all viewings, or make a class method on it that took a user and conversation and checked if there already was one, then created a new one or updated the existing one if you only wanted to store the latest.
|
# ? Mar 14, 2009 04:27 |
|
That's what I'm already doing though. I really appreciate all the help with this but please start talking about something else guys. I'm already doing what people are suggesting which tells me that I'm already doing it the best way I can, or I'm doing it the way I should. Thanks to everyone though.
|
# ? Mar 14, 2009 05:14 |
|
Ok gently caress it, here's what I did instead. It's a tale of woe and sadness, a knight's frustration and suffering. Many castles have fallen, many people left a bitter wreck at the side of the road. The amount of complication that had arisen out of all this became too much for my little medieval brain to bear, you're just going to have to trust me that it started to get pretty crazy and all for what I kept asking myself. So I've exposed my current_user object to the model using cattr_accessor, which is something yes I know I am not supposed to do. code:
This is just so much off my mind. :knight:
|
# ? Mar 14, 2009 18:41 |
|
Nolgthorn posted:This works like an absolute dream, I could not be happier
|
# ? Mar 16, 2009 04:50 |
|
Nolgthorn posted:This works like an absolute dream, I could not be happier, it's about 100% workload off my mind and you'll have to trust me on that. OOP and VMMPY and OSYYTR all be damned, this is too elegant to not use. Sorry, I really tried to be nice about this but you seem intent on ignoring the simple solutions we keep telling you about. So I can't be nice anymore. You better hope that nobody else has to see that code or ever maintain it, because they're going to have an absolute shitfit. YOU'RE DOING IT WRONG. That solution violates MVC, is fragile as hell, and is way too complicated. This is the absolute farthest thing from "elegant". If I had you fix one thing though, it would be this. Do not ever do this. Ever. WRONG: code:
code:
|
# ? Mar 16, 2009 17:12 |
|
Operation Atlas posted:RIGHT: I would be more inclined to try something like this: code:
code:
skidooer fucked around with this message at 18:03 on Mar 16, 2009 |
# ? Mar 16, 2009 17:51 |
|
skidooer posted:That will query the conversation_users table for every conversation row, exactly what Nolgthorn is trying to avoid. Yeah you're right, but this was the least-bad option of him insisting to have logic in the model that doesn't belong there. In my first reply to him I suggested a load from the controller, which is still the best, easiest, fastest, and most correct way of doing it.
|
# ? Mar 16, 2009 22:40 |
|
Just started learning Rails and came to find the thread. Looks dead in here. Am I missing a new Rails thread or are there just very few Rails guys here?
|
# ? Apr 1, 2009 06:54 |
|
KarmaticStylee posted:Just started learning Rails and came to find the thread. Looks dead in here. Am I missing a new Rails thread or are there just very few Rails guys here? There just aren't that many. You picked an exciting time to start learning though, rails 3 is coming out in a few months, and it's going to be awesome. Use http://apidock.com for looking stuff up, keep your controllers small, and write tests.
|
# ? Apr 1, 2009 07:00 |
|
Pardot posted:There just aren't that many. You picked an exciting time to start learning though, rails 3 is coming out in a few months, and it's going to be awesome. Thanks for the greeting! And yes, I'm really excited. Reading about the Rails 3 launch is what made me take the plunge and start learning. Right now I'm reading the half-finished 3rd Edition of Agile -- at least a good portion is up-to-date with the web site having notes on parts that are not.
|
# ? Apr 1, 2009 07:06 |
|
That apidock site is great. I was previously unaware of it. I find the official ruby on rails guides to be well written too. They are usually my go-to place for looking something up quickly. http://guides.rubyonrails.org/
|
# ? Apr 1, 2009 18:30 |
|
I have a Product, and it has a single Category, and a single Subcategory. The Category model has many Subcategories. Both Category and Subcategory have a to_param method which specifies a url-safe slug. I would like to setup a route that looks like the following: /products/:category_slug /products/:category_slug/:subcategory_slug All I have been able to get so far is /products/:category_slug/subcategory/:subcategory_slug Is there a way to accomplish this with nested resources, or should I just create a specific route for each? Also, I have a legacy table for related products. All it has is a left_id and a right_id. What is the best way to accomplish this in rails? I looked into nested_set and acts_as_tree stuff, but that seems like it might be a bit much for this. I could do a normal join model, but I guess what is throwing me off is both columns will be pointing to the same class (Product).
|
# ? Apr 5, 2009 16:34 |
|
Anveo posted:Also, I have a legacy table for related products. All it has is a left_id and a right_id. What is the best way to accomplish this in rails? I looked into nested_set and acts_as_tree stuff, but that seems like it might be a bit much for this. I could do a normal join model, but I guess what is throwing me off is both columns will be pointing to the same class (Product). I do something similar to this in one of my projects using Has And Belongs To Many. There is a table which contains user_id & community_id. Both have has_an_belongs_to_many set for each other in the model. the tricky part for me was that normal table creation also adds an id column which had to be removed for it to work correctly, but otherwise it does exactly what you expect: for each user_id, there are X number of communities, and vice-versa. on the other hand you are linking the same model to itself, which is slightly different, but still might work. another option might be to create a new attribute of the product and use serialize to make an array of the values in it. then you can just push in new ids for related products
|
# ? Apr 5, 2009 17:05 |
|
Anveo posted:Also, I have a legacy table for related products. All it has is a left_id and a right_id. What is the best way to accomplish this in rails? I looked into nested_set and acts_as_tree stuff, but that seems like it might be a bit much for this. I could do a normal join model, but I guess what is throwing me off is both columns will be pointing to the same class (Product). I had an issue that might be similar - I honestly can't quite tell for sure - that was answered in this thread a while ago. http://forums.somethingawful.com/showthread.php?threadid=2585949&pagenumber=20&perpage=40#post351829056
|
# ? Apr 5, 2009 17:32 |
|
dustgun posted:I had an issue that might be similar - I honestly can't quite tell for sure - that was answered in this thread a while ago. Awesome, that worked! Although I had to stare at it for about 5 minutes to understand what was going on.
|
# ? Apr 5, 2009 18:39 |
|
|
# ? May 29, 2024 16:56 |
|
I'm trying to implement custom 404 pages using method_missing in my ApplicationController. This code:code:
|
# ? Apr 10, 2009 15:48 |