#RubyOnRails - 12 March 2019
« Back 1 day Forward 1 day »
[09:41:49] kidPalooma: Hello, I have a routing concern that defines a 'restore' route, helper method example: 'post_restore_path'. I am trying to generate this route with a polymorphic url helper: 'polymorphic_path(resource, format: :json, action: :restore)'. The problem is that it tries to call 'restore_posts_path' and not 'post_restore_path'. How do I make it call the right helper?
[09:45:02] kidPalooma: ok, I solved it: I needed to define the route inside the concern as post :restore, on: :member
[10:04:15] amperry: anyone here familiar with what I'm sure must be a common Devise error? I'm getting an "Invalid Email or password" error on a login form; cf. https://gist.github.com/amp108/98f01991da014b415d0020431b2cdffd
[10:41:14] Giorgio: how to enable this style of rails development loggin "↳ app/controllers/articles_controller.rb:20"
[12:47:39] amperry: hi folks, anyone know how to troubleshoot when '<%= yield %>' doesn't seem to yield anything?
[12:51:57] amperry: ss942: seems like I was missing a route. But where would I put the Rails.logger.error, assuming (as it was in this case) that no error was logged? (I.e., what 'some string' would I look for?)
[13:00:58] Giorgio: If no routes is defined. Rails should raise exception when you try to access specific action
[13:03:20] amperry: Giorgio: that's what I would have expected. But it simply silently declined to render anything in the '<%= yield %>' section.
[14:06:18] andywww: i have a sidekiq job queue which expires downloads within 24 hours of them being created, and in development I want to make that 1 minute. Is that time span typically something you’d put in the environment specific config files something like config.my_var = 1.minute?
[14:08:20] andywww: at the minute its in, say, /config/environments/development.rb but I’m not sure if thats the best place
[14:17:07] pavelz: hi we have a database with somewhat .valid? records. problem is if we want to update some fields and run validations on new data and not old one, is there a way to disable validations for old data and only verifiy what was changed?
[15:08:49] Sylario: @pavelz weird question, update_attributes or save will prevent to save invalid data, you can run valid? after saving without validation or select element according to updated_at and valid? them after that
[17:21:41] duleja: Anyone interested in chatting about active record and session data access in the model? :)
[17:27:49] duleja: well I just wanted to see how would someone approach getting session data in the model? I ended up using gem called "request_store" and defining method inside "Modules::RuntimeEnvironment" module
[17:29:16] duleja: I just wanted to ask for an approach for using session data inside rails model? I know that it is not good practice but ...
[17:32:57] duleja: bad.. but there is one already, project was not done by me... Basically I need to add an exception to all queries to certain table
[17:33:32] duleja: where I would check geo location condition in the model and add default_scope if location condition is true
[17:34:09] duleja: so all queries will pass through that default_scope if user is coming from that location... but like I said location is stored session
[17:35:11] duleja: I could add scope to every query on the whole project for that table but that seems worse than adding chain to already existing default scope with an if... I hope that I am not too confusing x)
[17:37:30] hahuang65: sorry, I'm a little confused here.. you have geolocation data in session store, but need it in default_scope?
[17:38:33] duleja: if user is coming from certain location i should add another scope to already existing default scope
[17:39:19] duleja: since I want all queries to that table altered if the user is coming from certain geo location
[17:41:39] duleja: So I created scope where only if geolocation condition is true this scope logic will be executed, and I added this scope to the already existing default_scope as a chain
[17:42:40] hahuang65: can you just make a "fake" default_scope in the controller, where you do like @user = User.find(x).with_geo(lat: lat, long: long) and then basically return a user with a scope attached to that object, and use @user everywhere?
[17:42:45] duleja: I tried to find more documentation on Modules::RuntimeEnvironment but no luck? First thing I came across that I can't find documentation for in rails though...
[17:43:29] duleja: @hahuang65 issue is that I need this exception ono the whole project not just one controller
[17:45:27] duleja: I need all queries coming to certain table to be altered if geolocation condition is true. So chaining another scope to default scope seems like okay solution even though I hate default_scopes...
[17:46:03] duleja: I thought on setting global variable in application_controller where I set session in the first place if the geolocation condition is true
[17:48:56] hahuang65: the controller calls everything for the view/api. I don't see how attaching a scope to the @user variable won't be able to hit all the queries you need changed.
[17:49:09] hahuang65: you're always going to be passing that @user to everything that needs to run a query, right?
[17:50:33] duleja: it is a list of records that is different based on the user location. and I have many places where queries to that table containing these records are defined
[17:51:36] duleja: so in order not to change all these, and I guess all others where I do joins and stuff with other tables I need a default_scope that will be used every time
[17:52:53] duleja: lets say I have a widget on the home_controller (responsible for the home page...) and there I am also querying this table, so I would need to go and add that scope to each query that is targeting this table in every controller
[20:01:40] cxl: Hi, if I am using rspec in a rails project, it creates a spec/spec_helper.rb file. Should I also keep test/test_helper.rb or does it replace it? In a new project with no specs or tests in spec/ and test/ ?