This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
We are all familiar with activerecord .find_in_batches. The main idea behind it is not allowing to load thousands of ActiveRecord objects in memory which would cause tear down the server. I looked at this method and I looked at `.group` which applies GROUP BY clause. Just for fun, I thought what if I receive these “grouped_by” data in batches, something like
scope.grouped_by_in_batches(group_by_column) do |batch, value|
batch is an array same as we get in case of `find_in_batches`
value is the grouped value of the column
end
Hence I worked on this idea, made a pull request which obliviously did not work, as this was not a common use case, thats all fine. I agree to it. Even I never got to use it till date. However in attempt to do so, I really enjoyed writing test cases for it, getting interacted with a couple of ruby/rails expertise. Feeling happy about it.
I simply needed one helper method which would help me highlight changes being made on any ActiveRecord object inside email. Below is one example of that I have come up with and would like to extend it in my future projects too.
It gave me some insights into ActiveRecord::Base#previous_changes and ActiveRecord::Base#reflections. Nice to learn such ActiveRecord features.
samg/diffy also helped me out decorating text changes
Adding to my MailerHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
How about accessing @request and @current_user in your mailer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
tweak 1: Make some column quick-editable on the index list page
Ok… so I want to be quickly able to edit few names, here on the same list page, something like below
Thats simply great!
Now it makes me quickly update any name there itself on the list page, <enter> will make it, <escape> will ignore it, and <tab> will move to the next one. awesome.
And to make it work I just need to have one line of code change
All I need to say is `editable_test_column`, and its done.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
And here how it works, you will need to define a couple of things
You need to define editable_text_column, this you could place inside app/admin/lib/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Next, I would love to quickly alter article type say having a dropdown there to save my time
tweak 2: quick editable dropdowns on list page
Ohh, now this is again great! … no? It actually updates the article type on value change. nice.
Let see the code behind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
CustomHelper is one of my helper modules that really helps me render dropdown the way I need, and provides me some nice options, one may choose to use the default rails select helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
I do have worked out several more tweaks like toggle button for boolean column, show/hide columns on the list page, auto-populate/suggest feature for string filters, one can make use ActiveAdmin icons too, then for one of my requirements I have set up the whole custom header and a dozens of custom pages. I would easily say that ActiveAdmin is just simple and awesome, one can really customize it to the extreme, the code structure will allow you to imagine and implement a number of custom scenarios.
I often thought of this, application user is actually modifying the email contents before mail gets delivered. And I just set one example of it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Working with chef resource deploy, faced several issues with Git provider, for examples
– enable_submodule does not work properly
– it does not get the latest code from submodules
– it does not allow you to choose specific branch and sha of any submodule
– in fact for main repo it does not allow you to switch to any specific branch and sha
– for some reason it says branch=version, who knows why ….
I tried correcting all above, and below is one of my examples, its working for me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
They are there to help us out find out dependencies easier
They should not be dependent on each other, if module A has concern :b, then there should exist paths “root/a.rb” and “/root/a/b.rb“. Though this we ourself have to make sure about concerns path by writing additional code at initialization
I always willing to write clean and neat code, and have end up maintaining my concerns the following ways
Reopening Class
Include Module
Extend ActiveSupport::Concern
I do have one doubt though, out of 3 approaches, which one is good for faster execution?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
While working on one of rails applications, as I usually tend to check whether user is logged in, specially in views as follows
<% if @current_user.nil? %>
<a href='url to login page'>
<% else %>
<a href='some url where logged in user have access'>
<% end %>
And over some period I found this pattern repeating everywhere.
I thought of DRYing it, I wanted to have a kind of before_filter for every link that appear on the page, every link should go for login if that page or feature require user entity. and this should be handled by a common thing, similar to before_filter: login_require, on server side. I intend to achieve similar in views. A while back when I read up about html5 custom data attribute, and unobtrusive javascript etc, referring to them, I got one idea as described below, though it is not something that I am making use of custom data attribute exactly, but I found this idea useful and working. May be someone would have good suggestions here for me.
I will put any link which require user login as follows