|
I have a model setup question. I'm creating a database of video game release dates. The problem is, games sometimes don't get a specific release date. The release date might look like any of these: 2013 Spring 2013 April 21, 2013 What's the best way to setup my application to accommodate these different date types? My first thought was to create a separate Date model and create a has_one belongs_to relationship with the Game model. Though, I'm not sure how that would affect my view implementation. I'd probably have to do some ajaxy magic thing that asked what kind of release date type to assign (year, season, or exact date) before it allowed input of the release date. And of course, it would have to be updateable for when the release date changes or gets more precise.
|
# ? Jan 12, 2013 20:33 |
|
|
# ? May 15, 2024 02:53 |
|
Simple idea would be to flag whether they're month specific and day specific. If something is 2013 you could just save it as 01-01-2013. Then you could use a little class or method to determine how to display it.code:
|
# ? Jan 13, 2013 00:11 |
|
I too, would suggest a date field and a second field that describes the accuracy of the date. Then you could construct a method that puts the two together. released_at: 1-1-2013 period: 'quarter' looks like: Q1 2013 Or something like that. I'd imagine it's best to have a date column any way you decide to do it, just for sort order.
|
# ? Jan 13, 2013 03:45 |
|
Nolgthorn posted:I too, would suggest a date field and a second field that describes the accuracy of the date. Then you could construct a method that puts the two together. prom candy posted:Simple idea would be to flag whether they're month specific and day specific. If something is 2013 you could just save it as 01-01-2013. Then you could use a little class or method to determine how to display it. Thanks for the help. These suggestions worked. I'm going to have to be creative in my view to make selecting Q1..Q4 dates easy.
|
# ? Jan 13, 2013 04:02 |
|
I'm in love with this language. (Ruby, haven't started RoR yet though I'm nearly there.) Everything is just so... smooth and understandable and I've never absorbed as much information in such a short time in my life before. Maybe it's because this is the third language I learn the basics of and it's started clicking much faster, but regardless, this is awesome. Also, the newly updated Codecademy course for it seems to be awesome. http://www.codecademy.com/tracks/ruby I read through Learning Ruby The Hard Way (I had already read the python one) and then jumped into the second half of codecademy and it cleared up many things LRTHW had just kind of left in the air like symbols. Daynab fucked around with this message at 11:10 on Jan 14, 2013 |
# ? Jan 14, 2013 11:08 |
|
Here is a convenience I find lacking:Ruby code:
|
# ? Jan 14, 2013 16:00 |
|
Daynab posted:Maybe it's because this is the third language I learn the basics of and it's started clicking much faster, but regardless, this is awesome. Nope, ruby downright is an awesome language. You'll feel handcuffed and wonder why you have to do all this typing every time you have to go back to something else.
|
# ? Jan 14, 2013 16:13 |
Physical posted:Here is a convenience I find lacking: what does `MyModel.where('some_criteria = ?', my_var)` do?
|
|
# ? Jan 14, 2013 16:58 |
|
Physical posted:Here is a convenience I find lacking: I cannot reproduce this: Ruby code:
|
# ? Jan 14, 2013 17:01 |
|
Physical posted:Here is a convenience I find lacking: It seems like its how you are producing my_var. Is it being generated by some sort of count of query of its own that would return 0 instead of nil in the case of no results?
|
# ? Jan 14, 2013 17:55 |
|
I'm using MySQL and my where clauses is changed to Ruby code:
Doing this Ruby code:
e: It looks like it should work, I just have to examine what I have a little bit more. Thanks for confirming that it should work err'body. ee: Oh god it was because the value was being set to "", my numerous .nil? check's did nothing to prevent that, I am now using 'blank?' Physical fucked around with this message at 20:42 on Jan 14, 2013 |
# ? Jan 14, 2013 19:44 |
|
Physical posted:I'm using MySQL and my where clauses is changed to We've all had that happen. Plus side is that it's a learning experience!
|
# ? Jan 14, 2013 20:51 |
|
I still don't get what went wrong withRuby code:
|
# ? Jan 14, 2013 20:59 |
|
Physical posted:I still don't get what went wrong with code:
|
# ? Jan 14, 2013 21:20 |
|
Good to know. New question: I would like to create a sort of state-machine for my application. What I have is a form that can be in several different modes, the form has links on it to other items' edit forms that need to know what the current mode is from the base form. A example of this is the authenticity_token and how the app is aware of what the current_user is without having to pass it around in the forms. How do I reproduce this? e: looks like the session might be a means for this kind of functionality. Physical fucked around with this message at 23:06 on Jan 14, 2013 |
# ? Jan 14, 2013 22:54 |
|
This should be super easy, but I can't quite work it out: I want to create a simple form in rails that's not coupled to an ActiveRecord model. I simply want to hit a controller, and then I'll deal with the posted params from there. However, when I click my button, nothing happens - my controller never gets hit. The route is properly set up.Ruby code:
|
# ? Jan 15, 2013 00:47 |
|
Lexicon posted:This should be super easy, but I can't quite work it out: I want to create a simple form in rails that's not coupled to an ActiveRecord model. I simply want to hit a controller, and then I'll deal with the posted params from there. However, when I click my button, nothing happens - my controller never gets hit. The route is properly set up.
|
# ? Jan 15, 2013 01:19 |
|
Physical posted:Is it the difference between button and submit_tag? Or is your form tag crossing any div tags? Just tried submit_tag - same result. And I'm not sure what you mean by the latter point. The HAML is well formed, I'm pretty sure.
|
# ? Jan 15, 2013 02:58 |
|
I'd guess that it is probably missing the CSRF tags. Use the form_tag helper.
|
# ? Jan 15, 2013 04:04 |
Here's a stupid question: can I use just an html snippet as a partial? I just want to stick a plain <script> underscore.js template into one of my views. It sucks in haml because I want nesting and stuff without breaking, and ERB breaks because they both use the <% %> delimiters. e; meh, nevermind, I'm just going to use mustache delimiters instead. now do do a giant find/replace. I'm VIMming a little too hard today. A MIRACLE fucked around with this message at 15:58 on Jan 15, 2013 |
|
# ? Jan 15, 2013 15:41 |
|
You realize that you can put inline html inside haml, right? For example,code:
|
# ? Jan 15, 2013 17:24 |
Smol posted:You realize that you can put inline html inside haml, right? For example, yes but you still can't indent, correct?
|
|
# ? Jan 15, 2013 18:45 |
|
A MIRACLE posted:yes but you still can't indent, correct? You can if you put it in a haml :plain block, which doesn't escape: code:
HTML code:
|
# ? Jan 15, 2013 19:52 |
|
I'm not sure if I have seen this before but I feel like it exists. I want to create an object from a single link click using the built-in create/new routes. There is no need for a form, so I want to skip it.Ruby code:
e: Got it, but how do I pass parameters along to it? Ruby code:
eee: Oh new branch from master means the default database.yml file, which connected to the VM's DB instead of the one running on my Host machine. That was bizarre to experience. Physical fucked around with this message at 22:41 on Jan 16, 2013 |
# ? Jan 16, 2013 21:19 |
|
a
DONT THREAD ON ME fucked around with this message at 03:17 on Oct 8, 2014 |
# ? Jan 17, 2013 13:40 |
|
chumpchous posted:I had this exact question earlier today. I didn't from inputs from the user, but I did want some parameters forwarded.
|
# ? Jan 17, 2013 15:41 |
|
You guys might want to look into the :remote option on form tags- you can specify that it is an AJAX request via that flag. http://www.alfajango.com/blog/rails-3-remote-links-and-forms/
|
# ? Jan 17, 2013 22:20 |
|
chumpchous posted:I had this exact question earlier today. I didn't from inputs from the user, but I did want some parameters forwarded. It's customary to use the route helpers than to explicitly specify the controller/action/http method combination. For example, create_season_path is equivalent to your :controller => "seasons", :action => 'create',:method => 'post' definition.
|
# ? Jan 18, 2013 10:09 |
|
a
DONT THREAD ON ME fucked around with this message at 03:17 on Oct 8, 2014 |
# ? Jan 18, 2013 10:49 |
|
Yeah, I didn't think of the inflection issues at all.
|
# ? Jan 18, 2013 11:07 |
|
chumpchous posted:Yeah, this is something I was aware of, but couldn't make work at the time. I'm really liking rails, but dear god the emphasis on convention is frustrating when you're starting out. I generally gain a lot of understanding by looking at various examples and establishing a cause => effect relationship between things. In rails, the relationship is there, but it is rarely stated explicitly. Smol posted:For example, create_season_path is equivalent to your :controller => "seasons", :action => 'create',:method => 'post' definition. Ruby code:
|
# ? Jan 18, 2013 15:36 |
|
It's a good idea to run rake routes if you ever wonder what your real routes are. It lists all the shorthand methods for them as well (just add "_path" or "_url" to the end). ^^ You should be able to use just code:
|
# ? Jan 18, 2013 15:48 |
|
I have a general Ruby question. But since we don't have a Ruby thread and I am working with data from a Rails app, I hope it's okay that this goes here: I'm using Rubymotion, which lets you develop iOS apps in Ruby. I'm working with a locally hosted JSON resource, and a nifty gem called Bubblewrap, that wraps verbose iOS methods and makes them more Ruby-like. Anyway, here's my stumbling point. The Bubblewrap method to get and parse my JSON resource uses a callback block for when the request finishes. code:
The problem is, I don't know how to coerce the parsed JSON data (an array) into an instance variable. I can store the response, and work with it INSIDE the block, but I can't figure out how to get the parsed data outside of the block. So this works: code:
code:
code:
|
# ? Jan 19, 2013 07:29 |
|
Block scoping in ruby isn't super intuitive. Try setting the variable before the blockRuby code:
|
# ? Jan 19, 2013 09:21 |
|
That really doesn't help him, as the API is clearly asynchronous. That said, welcome to the wonderful world of asynchronous programming. Many things, like expecting to get useful return values from methods often don't exist in this world (especially in the node.js-esque callback hell side of things, which this API seems to be part of as well).
|
# ? Jan 19, 2013 13:49 |
|
Take a look at the API Driven Example part of the RubyMotion tutorial, specifically "Color.find". It looks like they're accomplishing what you want to do by passing a block into the method that uses BubbleWrap, using block.call in the callback, and setting the instance variable in that block.
|
# ? Jan 19, 2013 15:38 |
|
Civil Twilight posted:Take a look at the API Driven Example part of the RubyMotion tutorial, specifically "Color.find". It looks like they're accomplishing what you want to do by passing a block into the method that uses BubbleWrap, using block.call in the callback, and setting the instance variable in that block. Smol posted:That really doesn't help him, as the API is clearly asynchronous. That said, welcome to the wonderful world of asynchronous programming. Many things, like expecting to get useful return values from methods often don't exist in this world (especially in the node.js-esque callback hell side of things, which this API seems to be part of as well). The asynchronous nature of it is what's tripping me up for sure. This was a big help. I'm not familiar at all with this design pattern (or any design pattern), but after staring at the code for an hour, I was able to pass the response data into an object. Now I just have to maneuver those objects into my TableView and life will be good.
|
# ? Jan 19, 2013 18:52 |
|
Yep, event-driven programming can be quite complex. That said, it's a shame the Rubymotion devs didn't choose to use Fibers, using them can really help make event-driven programming more manageable.
|
# ? Jan 19, 2013 20:52 |
|
Warning: This ended up being a really stupid problem. Okay, I'm confused. I have a 3 model hierarchy, Series -> Seasons -> Episodes. code:
I've spent the day messing around with my controllers and routes (I nested the route on these 3 models, just to get an idea of how it works). I'm struggling a bit with rerouting everything, but that's fine. What I'm really confused about is that now, I can no longer create new seasons. They tell me I need to define a series_id. code:
(I believe the Season Exists error is because the season_id is nil, not because the season_number exists). Of course, I can't mass assigned the series_id, (and I don't want to). I've changed absolutely nothing on the models, aside from adding the default_scope order to Episodes. As I said, I've changed a lot with my controllers and routes, but none of that should apply to direct calls from within the console, right? What am I missing? edit: I figured it out. I had a helper function in my Series model, code:
code:
DONT THREAD ON ME fucked around with this message at 04:23 on Jan 21, 2013 |
# ? Jan 21, 2013 03:43 |
|
|
# ? May 15, 2024 02:53 |
|
Smol posted:Yep, event-driven programming can be quite complex. That said, it's a shame the Rubymotion devs didn't choose to use Fibers, using them can really help make event-driven programming more manageable. Funnily enough, Apple seems to have solved some of these asynchronus issues with Grand Central Dispatch. After a little bit of reading, I figured out how to get data out of my JSON objects and into Ruby objects. If anyone is interested, there's a project on github here which was a huge help.
|
# ? Jan 21, 2013 08:23 |