|
Is there a way I can manually execute the validtors that are listed on a model using the validates(*attributes) method? I can get a list of them using Model.validators, but how would I then easily apply those to the instance I have? I want to skip the ones that use the validates_with clause and only run the ones that do validates(*args) e.g. Ruby code:
ee: Here's my current dilema: how do I move this code to a module? Currently this doesn't work. eee: add included do to the module, this seems to work. Ruby code:
Ruby code:
KoRMaK fucked around with this message at 16:58 on Nov 15, 2013 |
# ¿ Nov 15, 2013 15:39 |
|
|
# ¿ May 16, 2024 01:43 |
|
I'm trying to incoporate facebook login via omniauth with devise. Users can login via facebook, but it broke the regular devise login. I'm getting a wierd error when a user does the ole devise loginRuby code:
I have created a sessions_controller.rb that inherits from Devise::SessionsController but it looks like it is not overriding the gemmed version that comes with devise. How do I override the sessions_controller? I set the routes for it to this ruby posted:devise_for :users, :controllers => {:sessions => "sessions"} I also have tried overrideing require_no_authentication in the sessions_controller.rb but it never seems to called. e: drat, I forgot the s in :controllers KoRMaK fucked around with this message at 18:23 on Nov 19, 2013 |
# ¿ Nov 19, 2013 18:17 |
|
kayakyakr posted:What directions are you following for using omniauth with devise? I have a working devise + omniauth (for facebook, google, etc) and I don't have my sessions controller overridden. It doesn't talk about devise, so I'm filling in those gaps myself and with this gist https://gist.github.com/schleg/993566 Maybe I should follow this guide https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview KoRMaK fucked around with this message at 21:19 on Nov 19, 2013 |
# ¿ Nov 19, 2013 21:15 |
|
Sweet, I have devise and facebook login working side by side. I had to override registrations and sessions to handle the two properly. New question: how do I keep heroku from taking forever when doing the assets:precompile step? I added ckeditor to my vendor/javascripts folder and I am pretty sure that is what is taking it so long. I never change the files in that directory, so why does it precompile on each push? I want it to only precompile if there are differences. In case anyone here wants to check out what I've been working on, you can find it at http://marquee.liquid-software.com It lets you create conversation threads connected to any gps location. Kind of like yelp, but instead of being tied to a business you can tie it to any arbitrary location.
|
# ¿ Nov 20, 2013 17:18 |
|
There were a couple issues I ran into while trying to run my dev environment on windows and I eventually just jumped into running my own linux VM. I'm glad I did it. Linux isn't that scary and the gnome desktop is basically OSX. I like it alot now, and I've learned so much and I was able to learn at my own pace.
|
# ¿ Nov 23, 2013 22:41 |
|
Yep. That works. From 600 seconds down to 6 seconds. Thanks. Since I'm on heroku I had to add the builder pack to my app.
|
# ¿ Dec 1, 2013 23:23 |
|
a_big_dog posted:This is a Rails thread. Surely Heroku is synonymous enough with Rails that discussion of it is worthy of a place in this thread? I'd think any talk about getting a rails app working on the Internet is appropriate for this thread.
|
# ¿ Dec 15, 2013 23:54 |
|
prom candy posted:Yeah and what we're discussing is tricking Heroku into thinking your dyno is active in order to not get it put to sleep. If everyone was to keep their free-tier dynos active at all times they wouldn't be able to offer the free-tier.
|
# ¿ Dec 16, 2013 05:09 |
|
I'd like to alter the "rails generate Scaffold MyModel" behavior. I need to make changes to the way models and controllers are spit out in addition to creating some new view files beyond the standard index/form/edit/show. As a plus, it would be nice if I could also alter an existing model to add a relationship clause to the new Scaffold-ed model. I read this top to bottom http://guides.rubyonrails.org/generators.html#first-contact but it hasn't fully clicked and I can't find an implemented example. I'm looking around in my railities folder and think I probably will copy those files for a start. I'd like to add this behavior in addition to the default scaffold behavior so I can chose when I want to use it. e.g. rails generate Scaffold and rails generate MyScaffold would both work. Is this possible?
|
# ¿ Jan 16, 2014 20:40 |
|
I'm still trying to make my own scaffold generator. For some reason, it cannot find active_record. I have no idea whats going wrong, I've been at this for a couple days. I monkey patched the scaffold_generator and it worked fine. Now I am trying to refactor that to a separate comand so we can scaffold for two different things (generate scaffold MyTest vs generate scaffold_dependency MyTest) Here are the classes that I copied and customized. These files are all located under lib/generators/* These files were all copied from the railties gem folder and then modified e.g. railties/lib/rails/generators/rails/* Ruby code:
Ruby code:
Ruby code:
Ruby code:
KoRMaK fucked around with this message at 17:24 on Jan 19, 2014 |
# ¿ Jan 19, 2014 17:21 |
|
Here's an example: @my_thing.persons.includes(:location).order("'persons.role' ASC, 'locations.name' ASC") The above doesn't work. The sql changes the column names via a "as" call and so the order by clause is effectively useless because person.role and locations.name aren't available. Uggghh it was a typo. I got too use to making things plural and person.role was typed as person.roles in the order clause. I'd like to make this the default scope for that relationship on the my_thing model. I tried this but it doesn't work Ruby code:
Ughhh 2: The has_many declaration works fine. Its the stupid caching we have that was screwing up the render. It didn't think there was any change so it kept showing me the old cached render. KoRMaK fucked around with this message at 17:24 on Jan 24, 2014 |
# ¿ Jan 24, 2014 17:02 |
|
Defghanistan posted:I am sorry to have to post with such a simple question but I've been internetting hard for about 12 hours and cant find a solution that works for me, which is crazy due to how simple of a problem this is. v is already the value you want. No need for v.last, just v
|
# ¿ Jan 28, 2014 17:24 |
|
Peristalsis posted:Bummer.
|
# ¿ Jan 30, 2014 18:29 |
|
These are code blocks right? (the failure/succes.html{} bit)Ruby code:
I'm using inherited_resources. I've come accross a situation where both my .js and .html responses should be the same. How do I combine them? Ruby code:
Ruby code:
Ruby code:
|
# ¿ Feb 3, 2014 16:21 |
|
kayakyakr posted:try: edit: oh duh, the help page does inform me of .all http://apidock.com/rails/ActionController/MimeResponds/Collector e: Found it down the page here http://edgeapi.rubyonrails.org/classes/ActionController/MimeResponds.html Ruby code:
Ruby code:
KoRMaK fucked around with this message at 17:54 on Feb 3, 2014 |
# ¿ Feb 3, 2014 17:42 |
|
kayakyakr posted:I also believe that it falls through (or fails to do so). So if you have success.json on the first line and then success.all on the second line, it'll respond with the json line and not the all line. Can I do any magic with that or do I have to build a separate function and call it from each success.whatever call?
|
# ¿ Feb 3, 2014 23:06 |
|
Just do a website with a three model relationship with jquery plugins, bootstrap, modals, ajax and angular.
|
# ¿ Feb 4, 2014 04:36 |
|
Ruby code:
Ruby code:
|
# ¿ Feb 4, 2014 14:48 |
|
I have some code that repeats in all of my controller functions, so I'd like to move it to a module as a method. It uses "super" though, and this is where the thing falls apart. How do I pass the "super" method to be invoked by the helper function, or how do I run the edit_helper inline as a proc or something so that "super" makes sense?Ruby code:
|
# ¿ Feb 14, 2014 14:58 |
|
Phummus posted:I'm cross-posting this from the general programming thread:
|
# ¿ Feb 27, 2014 19:36 |
|
Heyyyy, I just learned how to override a column name with a method on Active record and still be able to get the column (db) value. This causes a stack overflow due to recursion Ruby code:
Ruby code:
|
# ¿ Mar 26, 2014 15:15 |
|
Has anyone had experience with CanCan? I have class_b which has a relationship to class_a. I want the load_and_authorize_resource call that cancan provides to authorize class_b's actions based on it's relationship to class_a. The documentation for cancan isn't clear about this, and I've tried the :parent and :through methods but it doesn't seem to be right.
|
# ¿ Apr 17, 2014 16:56 |
|
kayakyakr posted:1) You should switch to CanCanCan as soon as you are able. CanCan has been abandoned by the creator and taken over by a group of others poo poo, I had overridden find_resource instead. KoRMaK fucked around with this message at 18:46 on Apr 17, 2014 |
# ¿ Apr 17, 2014 17:11 |
|
Here's a more general question, how do I override a method that is used as a prepend_filter? Instead of doing before_action :load_resource, I'd rather just override the load_resource method from cancan https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_resource.rb#L29 When I define the method in my controller, it doesn't ever get called. Why is that?
|
# ¿ Apr 17, 2014 18:46 |
|
kayakyakr posted:1) You should switch to CanCanCan as soon as you are able. CanCan has been abandoned by the creator and taken over by a group of others I did the above, and it doesn't seem to work. Can you explain what the flow should be? Like, how do I get cancan to use the class_a that I loaded to do authing?
|
# ¿ Apr 17, 2014 21:27 |
|
kayakyakr posted:authorize_resource checks for an instance variable of the same name as the class. for MyClass it's looking for @my_class or @my_classes (on index) to authorize.
|
# ¿ Apr 17, 2014 21:52 |
|
Wow, I just had a small error result in hours of confusion and lost work time. "Hash.key(:my_key)" is not the same as :Hash.key?(:my_key)" I knew this, I utilize both a bunch. I just overlooked the "?" It's kind of nice to feel so young and stupid again. (the load_resource solution kayakyakr suggested would have worked immediately if I hadn't made that mistake.)
|
# ¿ Apr 18, 2014 02:02 |
|
Putting simple Logger output messages inside of gems has revealed so much understanding to me and I can't beleive I didn't think to do this sooner. I the reason why I haven't felt comfortable doing it sooner is because I wasn't sure where the folder was and didn't care, and something about the gems folder being sacred and shouldn't be edited. I've spent all yesterday, some of last night, and this morning debugging CanCan to learn more about why it works the way it does. It has been very enlightening. Just gotta remember to pull my logger messages out and any changes when I'm done. KoRMaK fucked around with this message at 15:28 on Apr 18, 2014 |
# ¿ Apr 18, 2014 15:24 |
|
I have a bunch of Model names that I stored downcased in my DB. So "MyClass" is stored as "myclass" I now need to go the inverse direction, and get the model name so I can constantize it, but I kind of screwed myself because I used downcase ("myclass") instead of underscore ("my_class"). Is there a way I can still find the Model MyClass from the string "myclass" and not "my_class"?
|
# ¿ Apr 20, 2014 18:44 |
|
Arachnamus posted:Just iterate through the model filenames on the filesystem and find matches in the DB, then correct the DB entries to be something more useful. Or do them by hand, surely there's not that many? Creating a map would be good though. Since they are all ActiveRecord descendants I could do this ActiveRecord::Base.descendants or loop through the file system as suggested.
|
# ¿ Apr 20, 2014 23:06 |
|
Smol posted:Search for matching constants with Module.constants. Ruby code:
|
# ¿ Apr 21, 2014 01:28 |
|
So the purpose of this was to dynamically reflect a fields requiredness to the user on forms. Our app also allows users to select any field to be required, but hadn't integrated a way to reflect the model level requirements (validates presence stuff). Now we can reflect both to the user! Lame, but exciting. Rails is fun.
|
# ¿ Apr 21, 2014 06:11 |
|
Is there a way to make a two sided polymorphic join table? The join table would be: object_id object_type related_item_id related_item_type
|
# ¿ Apr 24, 2014 21:11 |
|
Oh, derp, I can probably get this done with using as: on the object side. I've figured something similar to this out before, it's just a little hazy remembering the nuances of the has many options. The one I always forge is that as defines the column name you want the current object to masquarde as.
|
# ¿ Apr 24, 2014 22:51 |
|
I have a custom getter/setter that I want to run through validator using validates :field, :format => {my_options} But the statement seems to ignore the validator. Is there a way to bridge the built-in validates feature with my own custom getter/setter?
|
# ¿ May 1, 2014 16:54 |
|
fruition posted:Took me literally 10 hours to figure out how to clean install Ruby on Rails, Git, and Heroku on Ubuntu. The learning curve apparently starts before you even get your environment setup. There's just too many outdated guides and poo poo, I may be a retard but I feel like it should be easier to setup.
|
# ¿ May 2, 2014 14:21 |
|
In a view, I'm doing some cachingRuby code:
|
# ¿ May 2, 2014 21:02 |
|
KoRMaK posted:In a view, I'm doing some caching
|
# ¿ May 4, 2014 16:51 |
|
I'm using url_for on an object that has an :as clause in it's route. The proper helper is "myscope_mymodel_path" code:
|
# ¿ May 12, 2014 17:55 |
|
|
# ¿ May 16, 2024 01:43 |
|
I wrote a module and a helper to figure this out. the Module goes on the object and enables it to respond to a method that returns it's nested route prefix. The helper figures out if it should turn that into a [:prefix, @item] array or if just @item will suffice.
|
# ¿ May 13, 2014 15:26 |