|
Physical posted:Why did the Jedi version not work? What is the point of non-@ members, when are they appropriate? It's ambiguious between setting a local varaiable and calling the #name= method. If you to call the method use self.name='mickey mouse'
|
# ? Oct 31, 2012 16:30 |
|
|
# ? May 30, 2024 09:14 |
`@name` becomes an instance variable, `name` will just be local to the `initialize` method, and will be garbage-collected when the method is finished executing.
|
|
# ? Oct 31, 2012 16:32 |
|
A MIRACLE posted:`@name` becomes an instance variable, `name` will just be local to the `initialize` method, and will be garbage-collected when the method is finished executing. It'll be out of scope. Garbage collection is an implementation detail.
|
# ? Oct 31, 2012 17:32 |
|
Wow something awesome just happened. I made Rails crash in a spectacular way by inspecting f in a form_for.... It crashed my VM so hard I couldn't even scroll to read it. I was doing this twice, not realizing it. When I got it down to 1 time I was able to read it and realized it contained like everything about our rails app. Routes, config stuff, totally unrelated classes, it went on forever making my scrollbar like 5px high. It did give me insight into what the hell f is a little bit and it's apparent magic.
|
# ? Oct 31, 2012 19:08 |
|
I have to populate a table with some initial application data, is it ok to do it with a migration?
|
# ? Nov 1, 2012 14:39 |
|
Physical posted:I have to populate a table with some initial application data, is it ok to do it with a migration? Populating initial data is what seeds are for, not migrations.
|
# ? Nov 1, 2012 14:43 |
|
Obsurveyor posted:Populating initial data is what seeds are for, not migrations.
|
# ? Nov 1, 2012 15:25 |
|
Physical posted:This is for a production database. Seed file will drop the current one will it not?
|
# ? Nov 1, 2012 15:32 |
Don't put it in a migration. That poo poo is a nightmare to maintain, esp when you bring new devs on.
|
|
# ? Nov 1, 2012 15:52 |
|
Just write your seed code in a way that it won't override existing data if possible.
|
# ? Nov 1, 2012 15:59 |
|
Ruby code:
|
# ? Nov 1, 2012 19:12 |
|
What does the super action do and why are you calling it in the middle of your method? Also why did you name one variable defaultsettings and one variables field_settings? That's just ugly.
|
# ? Nov 1, 2012 19:15 |
|
prom candy posted:What does the super action do and why are you calling it in the middle of your method? Also why did you name one variable defaultsettings and one variables field_settings? That's just ugly.
|
# ? Nov 1, 2012 19:20 |
|
Probably when you call super it's rendering the template, so anything that happens afterward is irrelevant.
|
# ? Nov 1, 2012 19:21 |
|
Is anyone at Rubyconf?
|
# ? Nov 1, 2012 21:42 |
|
MrDoDo posted:Is anyone at Rubyconf?
|
# ? Nov 2, 2012 03:13 |
|
I didn't quit my job quite early enough.
|
# ? Nov 2, 2012 04:18 |
I'm going to try damned hard to make RailsConf in Portland next April.
|
|
# ? Nov 2, 2012 16:33 |
|
A MIRACLE posted:I'm going to try damned hard to make RailsConf in Portland next April. Doc Hawkins posted:I didn't quit my job quite early enough.
|
# ? Nov 2, 2012 16:38 |
|
Physical posted:Didn't even know RubyConf was a thing. I'd assume soon enough to go to rubyconf. Speaking of conferences, we just recently set the date for the next Waza. It was really great last year, check it out http://waza.heroku.com/
|
# ? Nov 2, 2012 17:47 |
|
In ActiveRecord, Is there a good way to coalesce two (in this case) associations with the same model to form another, cleanly? If I lost you, here's what I'm trying to do: I have a Transaction model that's acting as a sort of audit log for transactions of virtual currency within the software. The Transaction model has two polymorphic attributes: receivable and payable. Think of a receivable or payable as "an entity that can pay or receive currency". In this case, my User model has two associations with Transaction: credits where the User is a receivable and debits where the User is a payable. What I want to do is have a third association, transactions that coalesces credits and debits. I want it to be an association and not simply a method on User so I can chain and scope it. I'm having a REALLY hard time writing an association definition that should read like "has many :transactions where User is either a receivable or a payable".
|
# ? Nov 3, 2012 00:01 |
This is probably a really stupid question but I can't figure out what's going on. I'm pretty sure that initially, when I went to run Rails locally for development, my assets would refresh upon page load if I updated my CSS. For example, I have a background image set right now that won't go away if I remove the code and refresh the page (or even restart the server, it seems like). I did precompile the code and push the code to Heroku, but even based on the research I did online, it seems as if rake assets:clean does nothing (as it just removes the public/assets folder). I'm still running WEBrick in development mode as far as I can tell, but removing the line code:
|
|
# ? Nov 3, 2012 01:09 |
|
Have you read this article https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar ?
|
# ? Nov 3, 2012 01:17 |
Pardot posted:Have you read this article https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar ? That didn't seem to help me as much as http://edgeguides.rubyonrails.org/asset_pipeline.html#local-precompilation The non-edge version has a bunch of stuff going on, but this one line in the link above seems to resolve the problem: code:
|
|
# ? Nov 3, 2012 01:56 |
|
Shame Boner posted:I'm having a REALLY hard time writing an association definition that should read like "has many :transactions where User is either a receivable or a payable". Ruby code:
|
# ? Nov 3, 2012 13:33 |
Okay, I have a new problem! I tried asking in the Rails IRC but no one seems to want to help, though it's likely a pretty basic relationship question I'm not fully understanding. https://gist.github.com/0fe5cf9093b21f4f632f I apologize if the code is really bad/adds a few things that don't need to exist as I'm still trying to get used to how Rails works. I want to have comments for each post that is made on my website -- and the logic I have is that users have many comments, and I suppose that the posts have many comments through the users. I do have that relationship added (though it doesn't seem to be doing anything in particular), and I feel as if all of my table references are correct (though I haven't added anything to users as I'm using devise and didn't feel like I needed to add anything as the post is a separate object itself). I can create comments on posts in development testing, but it appears that the created objects are not creating a post_id property for the post reference, and I cannot find comments for a given post as a result. If anyone can tell me what I'm doing wrong, I'd really appreciate it. I've read some documentation and a lot of searching, but a problem I notice with Rails is that everything seems to move so quickly development-wise that there is a lot of outdated information as well as a lot of ways to accomplish different things in Rails itself, which leads to an apparently lack of "definitive" answers. I do at least appreciate the work I've done with it so far because while it has some magic to it, I've also had to dig into some documentation and figure out how a lot of things work (in this case, I'm just having trouble).
|
|
# ? Nov 3, 2012 20:53 |
|
gucci void main posted:Okay, I have a new problem! I tried asking in the Rails IRC but no one seems to want to help, though it's likely a pretty basic relationship question I'm not fully understanding. You don't include the code that actually assigns comments to users/posts. I'm guessing that's where the issue lies. Your setup isn't magic, it won't do this for you. If you're not doing something like: code:
|
# ? Nov 3, 2012 21:03 |
I added the posts/comments controllers. Pardon some of the scaffolding/messy code, again, which will get fixed soon. As of right now, I can show all of the comments in general. I was also saving, at the very least, the user_id variable, so it can understand which account is making the comment. I'm not really sure where/when I should be passing in the post_id, so that's the biggest issue. Any way I've tried to do it in the posts_controller (since in theory I should be able to edit that attribute when the post page is loaded), I get an "undefined method 'post_id'" or "no post_id column" error, indicating that it doesn't exist, even though as far as I understand, I've defined it. If I show the attributes on a comment created, I get the following: {"id"=>1, "content"=>"asdfagasdfadsg", "posted"=>Sat, 03 Nov 2012 20:36:53 UTC +00:00, "user_id"=>1, "created_at"=>Sat, 03 Nov 2012 20:36:53 UTC +00:00, "updated_at"=>Sat, 03 Nov 2012 20:36:53 UTC +00:00}
|
|
# ? Nov 3, 2012 21:40 |
|
gucci void main posted:I'm not really sure where/when I should be passing in the post_id, so that's the biggest issue. Any way I've tried to do it in the posts_controller (since in theory I should be able to edit that attribute when the post page is loaded), I get an "undefined method 'post_id'" or "no post_id column" error, indicating that it doesn't exist, even though as far as I understand, I've defined it. http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association code:
|
# ? Nov 3, 2012 21:50 |
|
MVC design question here. Suppose we're modeling a restaurant order system. We've got Tabs, which would have attributes for table number and waiter. We'd have DrinkOrder, and FoodOrder, which would inherit from TabLineItem, and a Tab would have many TabLineItems. I want the "show" view for a Tab to have two forms, one for drink order, and one for food order. Am I correct in having controllers for food orders & drink orders, and those forms should be posting to the 'create' routes within those? Once something is successfully created, it should be bouncing them back to the "show" view for that given Tab? If that's the case, how do I handle the instance where there are validation errors and I need to render the "show" view for the Tab with the fields filled in and errors highlighted?
|
# ? Nov 4, 2012 17:11 |
|
kitten smoothie posted:Once something is successfully created, it should be bouncing them back to the "show" view for that given Tab? This is a bit vague, so I'm probably assuming too much: You can't successfully create something and then fail validation. In fact, if you're saving the TabLineItems under the Tab, the Tab is going to have to already exist(i.e. be saved) to save those. The Tab sounds like it could be extremely simple with just a table number, waiter and possibly a paid bool.
|
# ? Nov 5, 2012 01:44 |
|
Obsurveyor posted:This is a bit vague, so I'm probably assuming too much: You can't successfully create something and then fail validation. In fact, if you're saving the TabLineItems under the Tab, the Tab is going to have to already exist(i.e. be saved) to save those. The Tab sounds like it could be extremely simple with just a table number, waiter and possibly a paid bool. Sorry, I should clarify. The "Show" view for the Tab would have the waiter's name, table number, whatever other attributes about a Tab that aren't specific to the line items. I need two forms on that screen, one for adding a FoodOrder, one for a DrinkOrder, so through these you'd be adding all the line items that make up a dinner tab. There'd also be a table that listed the order line items associated with the Tab. If a user should screw up entering a FoodOrder and fail validation, I want the user to get bounced back to the Tab view they were at before, just with the bad fields highlighted. kitten smoothie fucked around with this message at 01:51 on Nov 5, 2012 |
# ? Nov 5, 2012 01:48 |
|
kitten smoothie posted:Sorry, I should clarify. The "Show" view for the Tab would have the waiter's name, table number, whatever other attributes about a Tab that aren't specific to the line items. Then there'd be two forms, one for adding a FoodOrder, one for a DrinkOrder, so through these you'd be adding all the line items that make up a dinner tab. Assuming you're following the Rails way(using resources in the routes), wouldn't your FoodOrder url look something like: /tab/:tab_id/food_order/new In the controller(probably not 100% correct, just going off the top of my head): code:
Obsurveyor fucked around with this message at 02:06 on Nov 5, 2012 |
# ? Nov 5, 2012 01:59 |
|
Obsurveyor posted:Assuming you're following the Rails way(using resources in the routes), wouldn't your FoodOrder url look something like: Ah, I was doing the first part of all that and routing things as you describe, but I didn't think to have the food_order new view basically reuse the guts of the tab view. I'll give that a go. Thanks!
|
# ? Nov 5, 2012 02:10 |
|
Backstory: I fix bugs and make enhancements to our Rails apps at work. We use a mix of Rails 1, 2, and 3 across about 15 apps! It's hell. We also use a mix-match of ERB, HAML, Prototype, jQuery, Backbone, and Spine depending on how new the app is. Not real familiar with the last two because those apps are still in QA and I haven't had much hands-on time. Anyway, my question is what should I use to go about making some AJAX-y site with dynamic updates? I want to make a simple chat server, something like StackExchange has. I have no problem creating a messageboard-type application from scratch, I can set up the DB and the views and controllers and all that stuff. It's the interactiveness that gets me. But it seems like there are 500 different templating systems and Javascript libraries, I honestly have no clue where to start. If you were going to make something like that where would you start? Is this more on the Javascript side than the Rails side? It seems like I'll have some sort of event loop that's polling the server for messages every 3 seconds or whatever, and then adding each incoming message to the page, and then an input box that sends a message to the server (to then save in the DB)
|
# ? Nov 5, 2012 22:07 |
IDK man I would honestly look into Node.js and websockets and stuff if you want to make a chat room. You could probably still hook it up to ActiveRecord if you want a sql log of the messages.
|
|
# ? Nov 5, 2012 22:10 |
|
A MIRACLE posted:IDK man I would honestly look into Node.js and websockets and stuff if you want to make a chat room. You could probably still hook it up to ActiveRecord if you want a sql log of the messages. I went through two Node tutorials yesterday, but I realized that's all server-side stuff, right? I'm not really having an issue with that end of it. I think I need to learn some more Javascript and it will make sense.
|
# ? Nov 5, 2012 22:13 |
|
Bob Morales posted:I went through two Node tutorials yesterday, but I realized that's all server-side stuff, right? I'm not really having an issue with that end of it. I think I need to learn some more Javascript and it will make sense. If a chatroom is what you need, peep this Meteor.js tutorial. It definitely piqued my interest in the framework.
|
# ? Nov 6, 2012 00:17 |
|
The Sweetling posted:If a chatroom is what you need, peep this Meteor.js tutorial. It definitely piqued my interest in the framework. Thanks for the link I will watch it tonight!
|
# ? Nov 6, 2012 01:36 |
|
|
# ? May 30, 2024 09:14 |
|
I'm building a rails app which will be hosted on Heroku and pulls data from an RDS MySql connection. Note that this connection is in addition to the Postgres connection to the database that's the persistence layer for the rails app itself. I've been able to authorize Heroku to connect to the RDS instance; however, it replaces CONFIG['DATABASE_URL'] with the mysql connection string, which is not a huge problem in itself. The thing is, the value stored there is a Mysql2 connection string: e.g. mysql2://user:pass@.... I want to use the mysql2 gem to connect to this database, and Mysql2::Client.new takes a hash of parameters. Short of doing a regex to pull out these parameters into a hash, is there a way to connect using a connection string?
|
# ? Nov 7, 2012 22:17 |