|
prom candy posted:I found installing postgres with homebrew to be a breeze. Although this wouldn't work on Heroku, this might be useful to anyone else who wants to skip asset pre-compilation. Helpful since our compilation process takes 10-15 minutes code:
code:
|
# ? Jul 24, 2012 16:46 |
|
|
# ? May 29, 2024 22:29 |
|
I'm writing an app that's basically a debugging proxy for a third-party web service. You change your endpoint to my app, it forwards the API request and returns the response, logs traffic, and allows you to fiddle with the data. One thing I'd like to add though, is a user-definable set of rules or assertions that each request is checked against. For instance, you might create a new rule of request[:version] > 4 and it would flag any requests using an old API version. Or if request[:method] == "foo" then request[:bar] == "baz" to highlight that you've not included recommended parameters. There'd be a web interface that you could define these, and they'd be loaded and run against each request that came through. Is there some sort of DSL and instance_eval trickery I can do here (I've never really looked at DSLs before), or is this more parser territory?
|
# ? Jul 25, 2012 00:20 |
|
Is there a way to do a scope that uses a related model in the search? I have Ruby code:
|
# ? Jul 30, 2012 16:12 |
|
Physical posted:Is there a way to do a scope that uses a related model in the search? Yeah, actually first do something like this: Ruby code:
Ruby code:
Ruby code:
manero fucked around with this message at 16:23 on Jul 30, 2012 |
# ? Jul 30, 2012 16:21 |
|
Thank you very much! That's close but I need the ModelA object returned, not the ModelB one. I need to find out which ModelA is linked to ModelB. Seems pretty simple using methods in the model, but I was hoping there was some super slick way to do it using a scope.
|
# ? Jul 30, 2012 16:49 |
|
code:
|
# ? Jul 30, 2012 17:15 |
|
prom candy posted:
|
# ? Jul 30, 2012 17:30 |
|
Physical posted:Yep thank you! That little line taught me a couple things too, that I can use the other model in the search clause, but I have to pluralize it (probably because that is what the actual SQL table is called) and that joining the table can use the :identifier. And it's pretty painless. I was pretty close, headed in the right direction, thanks for bringing me across the finish line. If you want to step it up a bunch, go from using LIKE to great built-in fulltext search. Pivotal released a gem that makes using the tsvector stuff easy with rails: https://github.com/casecommons/pg_search
|
# ? Jul 30, 2012 18:14 |
|
Pardot posted:If you want to step it up a bunch, go from using LIKE to great built-in fulltext search. Pivotal released a gem that makes using the tsvector stuff easy with rails: https://github.com/casecommons/pg_search This is awesome.
|
# ? Jul 30, 2012 18:21 |
|
So using the pg_search gem what would be the best way to also include my permissions? For example, say I have two models that I want to search, a page model with a secured flag and a post model that has active/inactive scopes:code:
|
# ? Aug 3, 2012 14:44 |
|
Hello thread, forgive me if I missed the answer to my question on an earlier page. I am a complete newbie, I am on windows 7 I have used the http://railsinstaller.org/ to install rails. Where do I go from here? I tried watching Michael Hartl's tutorial (and reading it) series but I keep getting into what I assume is dependency/gem version problems around chapter 3 so I have given that up for now. How do I gain the knowledge to actually start developing cool web applications?
|
# ? Aug 3, 2012 18:35 |
|
This isn't what you want to hear but developing on Windows is going to be a constant uphill battle for you. I would almost go so far as installing a Ubuntu VM for your web dev work, the Rails/Ruby dev community just does not seem to care as much about Windows/Windows users.
|
# ? Aug 3, 2012 18:42 |
|
prom candy posted:This isn't what you want to hear but developing on Windows is going to be a constant uphill battle for you. I would almost go so far as installing a Ubuntu VM for your web dev work, the Rails/Ruby dev community just does not seem to care as much about Windows/Windows users. I was afraid this would be the answer but I expected it. Now to decide I'd it its worth the trouble (going Ubuntu)
|
# ? Aug 3, 2012 18:59 |
|
Getting Ubuntu set up is a snap these days. If you're getting into web development being familiar with a non-Windows platform is going to be a huge boon to you, unless you want to go the full MS route (C#, IIS, cell phone clipped to your belt)
|
# ? Aug 3, 2012 19:02 |
|
code:
|
# ? Aug 3, 2012 19:15 |
|
prom candy posted:Getting Ubuntu set up is a snap these days. If you're getting into web development being familiar with a non-Windows platform is going to be a huge boon to you, unless you want to go the full MS route (C#, IIS, cell phone clipped to your belt) Is running a VM with Ubuntu similar enough to the real deal?
|
# ? Aug 3, 2012 19:28 |
|
Abrahamsen posted:Is running a VM with Ubuntu similar enough to the real deal?
|
# ? Aug 3, 2012 19:32 |
Jam2 posted:
returns self unless user evaluates falsy, otherwise returns all records of self's class that have a secured value of false in the database
|
|
# ? Aug 3, 2012 19:42 |
|
The idea is to return a chainable relation. I don't think what I'm trying to do is possible though.
|
# ? Aug 3, 2012 19:49 |
|
But it doesn't actually check the user against anything?
|
# ? Aug 3, 2012 20:24 |
|
It's checking it against nil, it's basically a really quick way to check if someone is logged in.
|
# ? Aug 3, 2012 21:37 |
prom candy posted:It's checking it against nil, it's basically a really quick way to check if someone is logged in. Just a thought, couldn't you skip this step by integrating CanCan or the like?
|
|
# ? Aug 3, 2012 22:19 |
|
I have CanCan integrated already, I'm not really clear on how it would integrate with pg search though, except maybe by checking can?(:read) on each. If you had another idea I'm definitely interested.
|
# ? Aug 4, 2012 01:32 |
|
I have a model that is to have a "related_items" relationship so I can do @mymodel.related_items And also, I'd like to go the other way, so that I can take an object that has been identified as a related_item for other objects and do @myitem.objects_that_relate_to_me The related item can be of multiple types, so I have a table setup with: related_item_id, related_item_type I have the second part, but not the first part. I thought the :through directive would do it for me but I couldn't quite understand how I could set the related_item_type field or even read it later. Is this possible using a :through model and I just gave up too soon? Physical fucked around with this message at 14:13 on Aug 6, 2012 |
# ? Aug 6, 2012 14:10 |
|
Does this answer your question? http://stackoverflow.com/questions/1683265/activerecord-has-many-through-and-polymorphic-associations
|
# ? Aug 6, 2012 15:36 |
|
prom candy posted:Does this answer your question? http://stackoverflow.com/questions/1683265/activerecord-has-many-through-and-polymorphic-associations
|
# ? Aug 6, 2012 15:43 |
|
Check out the guide on has_many :through relationships http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
|
# ? Aug 6, 2012 16:28 |
|
prom candy posted:Check out the guide on has_many :through relationships http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
|
# ? Aug 6, 2012 16:30 |
|
You can just deal with the join table like any other model. Can you post some of your actual code, it might make it easier for us to help you.
|
# ? Aug 6, 2012 17:18 |
|
Physical posted:Been reading it the last couple days, doesn't really tell me how to store extra data at creation time. Like the "appointment_date" field. They don't give an example on how to populate it. Ruby code:
|
# ? Aug 6, 2012 18:49 |
|
Anyone use Tire/ElasticSearch? I'm having some trouble doing pagination with multiple models. Suppose I have models Client and Contract. in my search controller method: Ruby code:
code:
If I were to do something like this, though, and only focus on the one model, it works fine. Ruby code:
|
# ? Aug 7, 2012 05:36 |
|
Cocoa Crispies posted:
New question related to polymorphic relationships, I have (made the mistakeof putting) the source_id and source_type fields in the same model of ModelC. Can the source and source_type be in the same table? Ruby code:
Ruby code:
Ruby code:
Physical fucked around with this message at 15:42 on Aug 7, 2012 |
# ? Aug 7, 2012 14:48 |
|
You're probably going to run into problems if you actually name your field "source." Does anyone know how to do an initial data insert for pg_search? I've added it to my project but my project has a ton of content already. Do I just need to loop over everything and save?
|
# ? Aug 7, 2012 17:39 |
|
I've run into an architectural challenge. I'm hoping some second opinions will help me organize this logic. My sites naked and www domains serve as entrypoints to numerous subdomains through which users interact with the site. models/region.rb Ruby code:
Ruby code:
lib/locale.rb Ruby code:
Ruby code:
locale in use dot rbs (some html.hamls) Ruby code:
Ruby code:
Ruby code:
Ruby code:
I've considered extending application_controller with a module called LocaleHelper to address this. lib/locale_helper.rb Ruby code:
|
# ? Aug 7, 2012 19:55 |
|
Jam2 posted:the problem is, the first time someone visits the site, they haven't yet visited a particualr region, so @locale.region is nil. This causes application errors. You should use the Null Object pattern here -- always initialize a locale, even if they haven't chosen one. You could have a NullLocale class that you can ask for its name: Ruby code:
That saves you from digging too deeply into the object itself.
|
# ? Aug 7, 2012 20:06 |
|
prom candy posted:Does this answer your question? http://stackoverflow.com/questions/1683265/activerecord-has-many-through-and-polymorphic-associations Then on the through table when you say Ruby code:
On one side of the relationship you must declare the :source => :alias_from_through_model and the :source_type => "String that you want in the item_type column" prom candy posted:You're probably going to run into problems if you actually name your field "source." e: Ooooooh! This one is even easier. You don't even have to put a relationship on the other models. The only one that needs it is the one with the polymorphic columns (*_id, *_type). And I did it with the column name as source too and there are no conflicts. Neat! Ruby code:
What if I want to change the names of the columns used? Let's say the column names are item_id and thing_type. It's stupid, but its just a hypothetical that I'm curious if there is an answer. Physical fucked around with this message at 20:40 on Aug 7, 2012 |
# ? Aug 7, 2012 20:12 |
|
manero posted:You should use the Null Object pattern here -- always initialize a locale, even if they haven't chosen one. You could have a NullLocale class that you can ask for its name: So my before_filter should look something like this then? Ruby code:
|
# ? Aug 7, 2012 20:21 |
|
Jam2 posted:So my before_filter should look something like this then? I'd say make a specific constructor in Locale (or just override initialize). Have it return either a legit Locale, or an instance of a NullLocale. Push it all down into the model. The controller/helper code should be clueless.
|
# ? Aug 7, 2012 20:23 |
|
manero posted:I'd say make a specific constructor in Locale (or just override initialize). Have it return either a legit Locale, or an instance of a NullLocale. Push it all down into the model. The controller/helper code should be clueless. I don't full understand. Is this the idea? Ruby code:
Jam2 fucked around with this message at 21:07 on Aug 7, 2012 |
# ? Aug 7, 2012 21:01 |
|
|
# ? May 29, 2024 22:29 |
|
Jam2 posted:I don't full understand. Is this the idea? Yeah, that's the basic idea. You'll want initialize_region() to return nil in the case that you couldn't initialize the region properly (so your || NullLocale.new falls through properly), but that's the general idea. Write tests!
|
# ? Aug 7, 2012 21:10 |