Curated list of episodes, bundled to help you on your learning path!
Videos of tech, infrastructure, hardware and software which non-instructional by nature.
Articles around software and tutorials.
Show your love and support while looking fancy.
can you make a part 2 of this where you add style to the content and links. Thank you
You should be able to simply add a class attribute to the link_to methods as you normally would to get the styling.
I like to keep my markup and style out of the controller and Models.
In this example Im adding 2 Data base Table column to one View Table with the Project name as the column and the manager as a small span. How can I recreate this with the json technic.
Project | Date | ActionsProject Name, project manager | 11/20/2011 | edit, change status action, delete
<td class="cell_stuff" ><%=link_to project. project, class: "stuff_link"%>
<span class="stuff"> <%= project.manager.full_name%> </span>
I see, keep in mind that the UsersDatatable is its own class and nor really part of the model or controller.
You could extract out the contents of the data method into its own class which I would probably do for larger tables.
As far as the classes on the td tags, that should be possible to do with their API. I'll look into it.
Perfect. will check that out.
FYI. Check your site permisión Display UI view. I can see the Delete Edit on your comment.
Thanks for the heads up. It wouldn't work since I'm doing server side authorization, but definitely shouldn't display.
Would it make sense to memoize the User.count call? I'm not super familiar with memoization, so I'm not sure whether it would benefit this specific situation.
Not really since it isn't being used elsewhere in the class. Keep in mind that the memorization is only valid for the lifecycle of the request and any further requests would no longer have the calculations stored.
How do you deal with enums in this setup? Say I have an integer column and I use enums in it - 0 is "no" and 1 is "yes". How do you filter for the strings rather than the integers within the table?
Great question. It really depends on the complexity to which you've modified the datatables. If you are using server side data and a full text engine, then I would store the 'yes' and 'no' values as part of the indexed data.
If you're using Rails 5.1.x then you could also use a virtual attribute to search on instead of the integer column.
Thanks for the quick reply. I am indeed using Rails 5.1.x. Do you have an example in the context of your demo in how I could accomplish this with virtual attributes? Never heard of these and am reading about them now.
You can check out https://www.driftingruby.com/episodes/virtual-columns-in-mysql and https://www.driftingruby.com/episodes/virtual-columns-with-json-data-types on Virtual Columns.
Thanks! Very useful. I understand the concept, but I'm still not sure what the best approach would be to use virtual attributes against an integer column and somehow extract a string from that. Would I need to define a virtual attribute for each integer that I have mapped as an enum? In my case I have up to 10 enums in some columns.
Just a fyi - I ended up creating my own custom select boxes that handle filtering for my enum columns.
Thanks for the great video! It has inspired me to create a gem that will make it possible for other rails developers to include jquery datatables into their project with serverside processing.
For those who are interested, you may find the gem here: https://github.com/brolycjw/datatable
Really cool! Another idea for your gem, allow a block with the listing of columns. Kind of like a small DSL for the ordering and selection of columns. I've been working on a project which takes the ideas of the Datatables and is basically a full rewrite; allowing pagination, individual column searching, column selection and ordering, saving custom reports and setting defaults, etc. It's a pretty large library so far, but not ready to share with the world.
That's sounds really nice, looking forward to its release!