Summarized using AI

Rails Already Supports View Components!

Andy Maleh • April 05, 2023 • Montréal, Canada • Talk

In the talk titled 'Rails Already Supports View Components!', Andy Maleh discusses how Rails inherently supports view components through existing features, advocating against over-engineering and unnecessary libraries. He emphasizes the importance of understanding the Rails framework to fully utilize its capabilities. The main points include:

  • Understanding View Components: View components help bridge the gap between visual design and programming, allowing developers to break down complex UI elements into manageable parts, such as nav bars and forms.

  • Avoiding Redundancy: Creating reusable components, like address forms, helps minimize code duplication and enhances maintainability. If a component is updated, all instances where it's used will reflect the changes automatically.

  • Maintaining Visual Consistency: Adhering to a style guide ensures uniformity in design across the application.

He provides numerous practical examples of view components:
- Address Forms: Reusable forms for billing and shipping addresses.
- Tables: Sortable, paginated, and filterable tables are commonly used in applications.
- Progress Bars and Accordions: UI elements that can encapsulate complex functionalities in simple components.

  • Building View Components in Rails: Maleh outlines methods for implementing view components using Rails partials, helpers, and presenters:

    • Rails Partials: These are essentially view components themselves and can be used effectively for UI rendering.
    • Rails Helpers: Useful for encapsulating logic, making them ideal for presenting model data and logic without markup.
    • Presenters: Custom Ruby classes that aggregate and transform model data to facilitate a cleaner presentation approach.
  • Customization and Flexibility: Each of these approaches allows for customization through locals and instance variables. Maleh highlights the use of Ruby blocks for passing extra markup to partials, showcasing their flexibility for more complex UI structures.

In conclusion, Maleh encourages Rails developers to leverage the built-in features for creating view components instead of relying on third-party libraries, advocating for a deeper exploration of Rails to promote productivity and maintainability in design. Overall, the talk emphasizes Rails’ capability in supporting MVC architecture effectively, highlighting best practices for using its tools for building modular, reusable components efficiently.

Rails Already Supports View Components!
Andy Maleh • April 05, 2023 • Montréal, Canada • Talk

There are several view component Ruby gems out there that were created and used by Rails developers in order to decompose application views into view components. Little did they know, Rails already supports view components!!! This talk will explain the various ways Rails already supports view components out of the box. And as part of that, it will demonstrate that the built-in Rails view component options are simpler, more Rails-idiomatic, and more conformant to the MVC pattern (Model-View-Controller). As such, they offer higher maintainability and productivity by avoiding the big great evil of Over-Engineering and NIH-Syndrome (Not Invented Here).

Montreal.rb Meetup April 2023

00:00:00.000 the topic of today is rails already supports few components uh like any I
00:00:06.960 mentioned I'm a senior software developer at lexop and I'll be talking about
00:00:12.320 why we should keep using rails in order to implement view components instead of
00:00:20.000 resorting to other options that are considered over engineering and
00:00:25.439 Reinventing the wheel so uh I mean this is a very big problem
00:00:30.960 in software engineering in general is people instead of people learning a library like rails well enough to just
00:00:37.320 use it correctly they end up thinking that some features are missing because they didn't do enough effort in
00:00:43.440 exploring rails itself and they end up writing their own library that reinvents the wheel and recreates everything that
00:00:50.399 rails already supports and this is what this talk is against it's basically against Reinventing the wheel before
00:00:57.420 you've studied rails well enough to figure out how to do things like view
00:01:02.579 components so uh to get started why do we need view components uh basically we
00:01:09.840 want to bridge the gap between visual thinking and visual programming so if somebody gives me a markup of a web a
00:01:18.240 website uh with a lot of elements I can basically divide and conquer the
00:01:24.960 elements and break them down into view components so that means you know I have a nav bar
00:01:30.900 I have a sidebar I have a bunch of tiles here and then I can put different things in different places so it's a way of
00:01:37.860 um dividing and conquering the work or the problems breaking problems down into
00:01:43.439 smaller Solutions and then gradually delivering features
00:01:49.700 also we want to avoid repeating ourselves so a very common view component is actually an address form so
00:01:58.140 often you would see a billing address form and a shipping address form we don't want to repeat ourselves by
00:02:03.180 writing that code twice we want to instead create a view component that's an address form and then reuse it
00:02:09.899 so reuse Solutions like an address form be more productive by being able to reuse Solutions instead of having to
00:02:16.140 rewrite them every time simplify the maintainability of the look and feel of
00:02:21.360 the website across the website by simply changing or updating one component and
00:02:27.060 if it's used in 20 places it'll get updated automatically in all of those 20 places
00:02:33.000 um lastly the third reason is to ensure consistent visual standards so
00:02:38.459 um if you're working with a web designer often they would give you sort of a style guide with a whole bunch of
00:02:45.540 components that they're envisioning the website to use and those components will
00:02:51.000 ensure the consistency of the look and feel of the website
00:02:57.300 so uh yeah that's about it so let's move to the next section which is view
00:03:02.819 component examples so I mean the first example which I already went through is an address form that's a very simple and
00:03:10.620 common one another one is address view meaning after you've entered the form and stored it into the web database then
00:03:17.940 we have an address view that will show you the address people you can do charting and graphing with
00:03:25.200 components like a bar chart and all you have to do is provide it with the data and it'll draw the bar chart for you so
00:03:31.200 that way you don't have to repeat yourself every time you need a bar chart um
00:03:37.920 okay my uh I'm sorry my slides are a bit wacky
00:03:42.959 that's the slide I was looking for two seconds ago uh about visual standards you want they help you comply with a
00:03:49.500 style guide like I mentioned uh also you can automate things like accessibility automate mobile responsiveness so if you
00:03:57.000 build a component that can support an iPhone an Android and an iPad then you
00:04:03.480 can reuse that component everywhere and it'll have support for all the mobile devices automatically
00:04:09.019 same with accessibility if you built it to be accessible with a keyboard instead
00:04:14.159 of a mouse or a voice control or stuff like that then it'll retain that and then you can reuse that in multiple
00:04:21.180 places including as well across browser compatibility
00:04:26.580 okay let's go back to view component examples so uh this is a very common one
00:04:32.880 which is a sortable table it's very often in business apps that we
00:04:38.520 would want to display a table of data and usually the columns are sortable so
00:04:44.340 that's a very common view component another one is a paginated table so this
00:04:52.199 is a table that includes Pages kind of like how you do a search on Google and
00:04:57.600 with a search engine and it would give you Pages at the bottom or the top you can also Implement your own paginated
00:05:03.780 table component um a third kind of component which we actually use at lexap is a filterable
00:05:09.900 table which is also used in mini e-commerce websites so they give you a table over here but then you have
00:05:15.120 filters on the side that lets you filter the table as well as full text search filtering
00:05:20.280 and those Solutions are combinable like you can build build one component that supports being filterable sortable and
00:05:27.000 uh passionatable
00:05:32.600 tabs if you want to have support for tabs that could be a component view component you can have a progress bar as
00:05:39.120 a view component that would update progress Based on data that it pulls from the back end
00:05:44.600 uh so yeah you would give it a URL and it would pull its data and give you progress you can build an accordion that
00:05:51.780 would hide information in those item two and item three but in item one is showing us the content so that's an
00:05:58.320 accordion component so I mean the sky is the limit these are just examples and they're very few compared to how many
00:06:05.699 components you can build you can build hundreds maybe thousands of components a few components
00:06:11.520 um so yeah menu bars calendar uh text editor and some components like
00:06:18.180 a text editor involve a JavaScript component a JavaScript element in it too so you can actually build components
00:06:25.319 that have JavaScript code combined with their code uh breadcrumb
00:06:32.880 a wizard so a multi-step Wizard or multi-step form lets you move from one
00:06:38.819 step to the next while allowing the user to enter data so select customer select
00:06:43.919 products ask sorry add basic data and then confirm data I mean this is often
00:06:49.380 used in e-commerce websites when you know or even restaurant ordering websites
00:06:55.860 and you could even even with games you can Implement components so if I were to implement clone deck Solitaire as a web
00:07:02.520 game every playing card is a component so that would be a good way of dividing
00:07:07.740 the user interface into components by making every playing card a component
00:07:15.600 so how do we build few components in rails and that's the main topic of today
00:07:21.599 uh so the first thing that you can use in rails to build view components is rails partials so a lot of people don't
00:07:28.860 realize that rails partials are view components it's unfortunate that some people try to
00:07:35.460 reinvent the wheels or create their own libraries to build few components in rails but rails
00:07:43.319 partials are already view components whenever so a partial is basically a partial view so a view is uh for example
00:07:50.880 if I load a page that enables me to edit the user profile that's the view which
00:07:57.360 is the profile view that's the full page partial is a part of the page and all
00:08:03.240 the name is a bit technical like rails partial it's a very technical name it
00:08:09.419 might not give people the impression that it's a component but it actually is exactly what a view component is so you
00:08:16.319 can basically create us and they're usually Erv files that start with with an underscore
00:08:21.800 and you can basically make an address form partial
00:08:27.960 in fact if you use rails scaffolding and you create a an address resource or
00:08:33.719 model it'll generate for you an address form automatically and it'll put it in its own partial
00:08:39.839 so that can get you uh already you know half the way there like half the way
00:08:46.140 towards having an address form component and then you can rename it like usually they would call it underscore form and
00:08:52.320 they would Nest it under addresses you can rename it as underscore address
00:08:57.660 underscore form and then to give it maybe a more explicit name and then reuse it elsewhere in your website not
00:09:04.740 just in the address pages uh but basically rails partials are helpful in building components uh to to
00:09:12.600 present view Concepts that have a lot of markup but little logic so usually partials will not have a lot of logic
00:09:19.500 that they might have an if and else statement here and there uh but not a lot of if else statements or
00:09:25.440 conditionals usually but they will have a lot of markup by markup I mean html so I mean here's an example of an
00:09:32.399 address form um it's using uh basic rail Syntax for building a form but basically it's
00:09:39.720 mixing some Erb scriplets which allow you to embed Ruby code in HTML with HTML
00:09:45.480 and that lets you build a form but this is basically and I mean this is the rest of the file but that that is basically a
00:09:52.800 self-contained view component that you can reuse anywhere so if I were to rename it to something more friendly
00:09:58.980 like address form I can reuse it anywhere which brings me to the next point if you're using it anywhere what
00:10:07.019 if I want to use it multiple times with different customizations well it is customizable via a feature in rails
00:10:13.620 called locals as well as instance variables request parameters and session variables so anything that you have
00:10:20.339 access to and Views and rails you have access to in partials as well so I can
00:10:26.160 locals are basically you can pass options to partial kind of
00:10:31.320 like in this syntax so I'm saying render in address form given an address model that's the shipping address and give it
00:10:37.380 a title of shipping address and those options will end up becoming local variables inside the partial so they
00:10:44.880 become available in the in the partial syntax so if I were to go back here to the code you see how we're using a title
00:10:50.100 at the top so there's a title variable at the top and that's basically coming from the locals so basically not only
00:10:58.560 can you build view components with rails partials but also you can make them fully customizable with local variables
00:11:04.740 or local options or you can if you set any instance variables they're going to become available in those partials if
00:11:11.640 you have request parameters they're available on those partials and if you have session variables they're also available
00:11:17.820 foreign one more thing that not many people are aware of is not only could you customize
00:11:25.680 rails partial by passing its options like locals like what is the title of the form and what is the address model
00:11:32.100 but also you can embed content within it if needed and customize it further so it
00:11:37.800 may accept nested content so suppose we want to build an address form that will give users extra instructions between
00:11:44.760 the title and the form over here and those extra instructions like a sort of
00:11:50.579 a hint or a tip could vary from page to page in your website or from an app to app well that's doable you can actually
00:11:58.260 accept nested content and partials so for example
00:12:04.620 this is how you do it you take advantage of the feature of Ruby blocks basically so some people don't know this you can
00:12:12.120 use Ruby blocks in Erb files with uh by while rendering partials so here we're
00:12:18.600 rendering in address form passing it's an address in a title but also we're opening a Ruby block and nesting content
00:12:24.899 that will be that is actually any kind of markup you want any arbitrary markup that will get embedded in the hint part
00:12:33.000 of the address form
00:12:39.899 um and within the address form code what we do is we add a yield call so where we
00:12:45.600 want the hint to appear which is between the title and the form we can add a yield call and that will yield that will
00:12:51.540 basically accept the block content that we Pat we could pass to a partial and embed it right there
00:13:00.000 so I mean to review how that ends up looking like yeah this is how the form
00:13:05.519 ends up looking like because we have a title we have a yield statement over here that will accept some content that
00:13:12.779 is passed from code that is using the partial and then here we have the form
00:13:22.260 so I mean this is demonstrating how partials are very very customizable and flexible they're not like
00:13:28.980 they're not like base uh how do I say it they're not very basic features of rails
00:13:34.860 they're actually quite Advanced and customizable uh so they can address a lot of use cases
00:13:40.760 uh now I'm going to go now into a few um uh how uh I'm gonna go into a few like a
00:13:48.720 couple of very Advanced features and and partials uh so usually a partial by
00:13:55.440 default by using a a block can accept one piece of content of markup that you
00:14:01.079 can insert somewhere in the partial what if you want to insert multiple pieces of content that's rarely needed but every
00:14:06.540 once in a while it might get needed uh you can basically repurpose a feature in
00:14:12.060 rails which is available in rails layouts and use it from partials instead of
00:14:17.940 layouts so I'll talk about this in a moment so suppose we have a an accordion widget that has a top and a bottom and
00:14:25.920 the top can accept a piece of content the bottom can accept another piece of content so I can actually pass it two
00:14:32.880 pieces of information markup instead of one so to do this you would say content
00:14:38.519 for accordion top you would use the ID of that content and then you would embed some markup and
00:14:44.880 then I can say content for bottom and then you render the partial if you do if you do those two lines ahead of the
00:14:51.000 partial the Dual accordion partial will then use that information I'll show you how it'll
00:14:57.120 also use the keyword yields but then it'll use an ID afterwards and as long as you match the ID you can pass it
00:15:03.420 multiple pieces of markup this is not necessarily needed all the time but
00:15:09.120 every once in a while it could solve a very good problem and you can go beyond that so this is the last bit of advanced
00:15:15.480 features of partials basically you can have an arbitrary number pieces of content embedded into a partial so if I
00:15:21.660 have an accordion with any number of sections within it could have three or five or 17 doesn't matter
00:15:29.660 you can pass it as many pieces of content as you want that you want to embed in it so if we go here we have
00:15:36.420 three of them and we're using an index and here you have to give the partial
00:15:42.000 the item count and then it'll figure out how to yield all of those three and embed them in the page so this is the
00:15:49.320 most advanced way of using rails partials and this is the code of the partial basically it uses the item count
00:15:56.060 and then as many times as that item count it'll execute this code which will yield dynamically the ID of the content
00:16:03.540 that will be that'll get embedded it can even add its own markup on top of it as well to make it an accordion
00:16:12.300 so uh okay let's go to the second method of use building view components now the next method is help rails helpers
00:16:19.620 uh so rails helpers are not Erb files they're actually methods and they're
00:16:24.839 useful for presenting view concepts with no markup usually and a lot of logic so unlike uh partials
00:16:32.339 which usually have a lot of markup and little logic helpers are the opposite of that they're helpful whenever you have
00:16:38.579 no markup and a lot of logic technically you can add markup within
00:16:44.519 rails helpers but it's highly discouraged uh it's don't do it and I'll show you why you shouldn't do it there
00:16:50.579 is a better alternative that I'm going to demonstrate in a moment but basically rails helpers are useful for things like
00:16:56.759 if you're pulling data from Models you can use rails helpers as sort of like
00:17:02.100 they're basically methods that are embedded in a helper module and usually those methods can act as presenters of
00:17:08.939 model data so for example if I have a select box with a bunch of provinces in
00:17:14.939 it uh I can make a helper that would provide me with the province provinces list
00:17:20.339 so here I can embed in a I can use the collection select rails built-in helper
00:17:27.780 for building a select box but when I pull in the provinces I I'm using another helper called provinces that
00:17:33.660 will give me the list of provinces and none of that is markup It's All Pure strings and array of strings basically
00:17:40.980 so this is the implementation of the helper this is a very very basic helper where
00:17:48.059 I'm just providing pure data that's not the best way of writing the code though A Better Way would be I'll
00:17:54.299 show you how the better the better ways to delegate to a model so we would have a model called country that you can give
00:17:59.820 it the name of the country and it would give you the provinces and that that would be the best way of implementing helpers but either way they're basically
00:18:06.539 presenters of information that doesn't have much markup in it and could have a lot of logic and so to offload the logic
00:18:14.880 from the Erb files it's not nice to write logic and scriptlets and Erb files you can move all of that logic to
00:18:20.580 helpers um so however we can go a level beyond that
00:18:25.919 we can uh you saw the select statement The Collection select statement that I
00:18:31.559 showed you earlier it's very verbal and it's and also on websites there will
00:18:37.500 be many times when I will need to show provinces so what I could do is build a province's component that will show a
00:18:44.700 province's select box story that basically um encapsulates everything about the
00:18:50.460 province's select box so that way here I can just say Province select instead of saying collection select and passing
00:18:56.039 into a whole bunch of options I'll abstract the whole idea out behind the word problem select and I'll pass that
00:19:02.640 the form and it does everything for me so that's the way where you can take helpers even further
00:19:08.220 um so a helper's another use of helpers is basically they can be customizations of existing
00:19:14.580 rails helpers like form helpers so the collection select uh method that I
00:19:19.620 showed you earlier is that as a rails built-in form Helper and here we're actually building a customization on top
00:19:24.840 of it that hides it and makes it only for provinces um
00:19:30.299 and um yeah so I mean this is the implementation and it hides all the
00:19:36.360 details however we can go even further we can customize them via method arguments so given that helpers are just
00:19:42.179 methods you can pass them arguments like prompt true and if I say prompt true it
00:19:47.580 means it's going to add a prompt at the at the top of the listed provinces and if I pass prompt false I can remove the
00:19:54.660 prompt so here prompt is false so I mean let me see if the previous version had the prompt I believe it did
00:20:01.140 let's go back yeah here it says please select uh and then it shows the provinces uh so
00:20:08.039 you can make that the default that could be a friendly default but then you can customize it so I can in a later version
00:20:14.520 here uh pass it to value of I mean this is the implementation of it but I can also
00:20:21.600 pass it at Value prompt false and it would hide the prompt so that's another example of customizing
00:20:28.260 view components um one other way of customizing helpers
00:20:33.419 is actually you can combine the two so you can combine helpers with partials and that's the reason why it's very
00:20:38.880 highly discouraged to use markup language inside helpers whenever you need to have HTML in a helper
00:20:45.860 delegate that to a partial so the helper here Province field helper can actually
00:20:51.660 render a partial within it so that way you can combine the two so any anytime
00:20:56.940 you have HTML push it to a partial anytime you have logic put it in a Helper and then you can make the helper
00:21:02.520 call the partial or the other way around that's a way of basically having you
00:21:09.960 know both options like you have the Best of Both Worlds at the same time now in rails without needing to use a third
00:21:15.960 party Library so whenever so I mean I can build this province field using this
00:21:21.299 partial uh that will uh hide so for example what
00:21:27.299 I what I just did is I upgraded The Province select box into a province field instead a field not only shows the
00:21:34.559 select box it also shows you the label in front of it so now this will include everything that's basically the div as
00:21:41.820 well as the label as well as the select box so that's we went to level of abstraction higher basically so now this
00:21:49.320 automated more code so that means I'm going to have to write less code now in the future if I need to use the province field and that's my combining partials
00:21:57.240 with helpers so any helper could render a partial and you can delegate any Erb
00:22:03.980 code to the partial but then do the logic in the helper
00:22:09.179 so let's mentioned that gives us the best of both worlds you can even pass it Ruby blocks so even
00:22:15.539 helpers can receive Ruby blocks so that way I can use the helper and then embed extra markup in it while using it inside
00:22:21.600 a view so you can go even at level even higher
00:22:26.820 so I mean already right now just with partials and helpers we have so much flexibility that uh
00:22:33.900 uh sadly I wish more software Engineers were aware of it because then they wouldn't have to use third-party
00:22:39.840 libraries for something that rails already supports uh however if you need even more flexibility the third thing
00:22:46.020 that you could do as presenters so presenters are a special form of models so they're classes they're just Ruby
00:22:52.500 classes that's what they are that can hide even more logic away so a helper gives
00:22:58.980 you a method methods in general are not recommended to be longer than say five lines of code
00:23:05.400 you can go up to 10 15 lines of code but if you find yourself going above 15 lines of code you're starting to have
00:23:13.740 too much logic in the helpers so then what you could do is actually break that logic into a class and have a full class
00:23:21.240 handle all the logic with all its permutations so you can create a presenter so a presenter will aggregate
00:23:28.980 or transform model data to present visually so if I have an address that I want to present in a single line you can
00:23:35.580 basically you don't want to add that logic to the address class because it's presentation logic it's not business
00:23:41.700 model logic it will basically Cloud the code of the address class which should
00:23:46.740 be more focused about the business so what you could do is create an address presenter and have a one-line summary method on it and that will summarize the
00:23:53.820 address so so technically you could do the same thing in a helper as well and a because
00:24:00.659 that helper helper methods are also presenters but presenters give you a level up over helpers by being able to
00:24:07.320 extract classes and then reuse them in multiple views so a helper usually uh
00:24:12.960 for example I might have an addresses helper module in rails that's focusing on address related pages in my rails app
00:24:19.940 whereas if you extract a presenter a presenter could be reused from any page in your app so it's a further
00:24:26.100 generalization of the presentation concept and um yeah and then I I just use it
00:24:32.880 like so I can shorten it so what you could do is combine presenters with helpers as well so I can make uh so here
00:24:39.000 if I go back I have to say address presenter new address one line summary if you're using this presenter a lot
00:24:45.840 many times I don't have to repeat myself I can just create a helper within my addresses helper module and I just call
00:24:53.880 it presenter and it infers the context from the fact that I'm within address pages and if I'm there I just say
00:25:01.500 presenter one line summary if I need to use multiple presenters for multiple models then I can change the name to
00:25:09.059 something else I can call it address presenter or shipping address presenter Etc but you can build your own abstractions with helpers that hide
00:25:16.620 presenters if you want that way the code in the view is very simple so so this is
00:25:21.960 an example of how you can hide the details of presenters behind helpers yeah I mean this is an address's
00:25:28.020 helper it has a presenter and it prevents me from repeating this code multiple times in The View
00:25:35.279 which is a great thing but also um
00:25:40.559 so yeah presenters are helpful also in making rails helper logic reusable for multiple places instead of embedding it
00:25:46.559 in a in one method I can hide excessive logic in rails helpers by creating
00:25:52.320 presenter classes um they're usually given that they're a
00:25:57.720 full-fledged Ruby class they're customizable either through the Constructor meaning the initialize method or ifu method Arguments for
00:26:05.400 specific methods on that presenter like one line summary that will do the work so you can give it extra options like I
00:26:12.120 can tell the one line summary to for example exclude the name of the person it just gives me give me the pure
00:26:18.720 address without the name of the person or stuff like that and presenters are usable either
00:26:25.799 directly from views so uh or from rails partials or from rails helpers so you
00:26:32.279 can use it from anywhere so um so that's pretty much it so I mean
00:26:38.520 to give you a summary of the talk why do we need few components to bridge the gap between visual thinking and visual
00:26:43.559 programming to avoid repeating ourselves and to ensure consistent visual
00:26:48.960 standards what are some examples address form at rescue bar chart sortable table
00:26:54.840 paginated table fill triple table tabs progress bar accordion menu bar calendar
00:26:59.880 Rich Text Editor Brett crumb wizard Etc and then how do we build few components
00:27:06.779 and rails we use rails partials which are Erb files beginning with underscore
00:27:12.299 rails helpers which are methods and presenters which are classes and with this with those three components
00:27:19.460 you can solve any problem with uh regarding view components so any view
00:27:25.679 component that you could dream up you can build with one of those three methods or a combination of them
00:27:32.880 and that's it that's that's the end of the talk this Begins the Q a section
00:27:41.460 uh you can go back to one of the uh
00:27:47.100 the Erb file you have a render method the first argument of the render method
00:27:52.200 is a string okay Erp file
00:27:57.600 let's see not this one maybe this no
00:28:04.380 yes here yeah so the First Advantage is the string easy the do you have like an
00:28:11.580 can we take advantage of meta programming yes yes you can
00:28:18.799 we actually do it uh I mean here at lexap we do that sometimes you pass a string that is
00:28:25.799 basically which uh partial you want to render and then you can dynamically vary the partial that will get rendered by a
00:28:31.860 helper so this is common practice yes yes
00:28:40.440 it's not very common I wouldn't say that's needed all the time I would say that's needed maybe less than ten or
00:28:46.559 five percent of the time but but it's it's common enough yeah
00:28:51.659 do you know we would really recommend meta programming in the application code
00:28:57.240 um generally though I would avoid it until the last possible moment only if
00:29:03.539 yeah exactly only if it's automating a lot of work that would save us hours
00:29:08.840 without a program like yeah without meta programming then or sorry with meta
00:29:15.480 programming versus without meta programming then then I would avoid it I tend to not use meta programming unless
00:29:20.820 really really need it yeah because sometimes when you and I would let
00:29:32.700 between the two meta programming should not be used just because it's cool that's a big problem sometimes where
00:29:38.399 people use it because it's cool because they can because you shouldn't do something just because you can it doesn't mean it's right it has to be
00:29:44.820 right in addition to being you know you being able to do to use it so yeah no not
00:29:50.340 necessarily foreign how do you test those components
00:29:58.919 um that's a very good question so if it's a rails partial it's an Erb file and it doesn't have that much logic so
00:30:04.860 usually it doesn't really need a test however it will get tested by System tests that QA Personnel right so if
00:30:12.779 there is a QA team that is writing their own automated test using selenium that will test all the rails partials but as
00:30:19.320 developers usually we don't write that much tests for them helpers are just pure Ruby codes so they're very very uh
00:30:25.440 testable it's very simple to test them presenters are even are the same they're
00:30:30.960 even more testable they're a class and you could do whatever you want with it I mean they're not more tests they're equally testable I guess so yeah both
00:30:37.320 helpers and presenters are very extremely testable but the
00:30:43.260 test like
00:30:48.299 off the page not decomponent specifically is that what you said
00:30:54.600 uh it depends so um in a component like this I might mark
00:30:59.760 this part so I might so I'm assuming the reason why we need a helper is there's a
00:31:04.980 lot of logic this is very simple actually this is so simple that we don't need a test for this but if there was an
00:31:10.320 FL statement in some logic I would add a test but I would mock this part I don't want to test the rendering so I would
00:31:17.159 mock it but I would test the if else statements and make sure that it's executing correctly based on options
00:31:22.260 that are passed as arguments the logic then you test the of the page
00:31:28.679 like two separate tests the pages will get tested by the QA people that write
00:31:33.840 system tests with fuselenium from a browser whereas the logic of the helpers will get tested with Ruby tests you had
00:31:40.260 a question go ahead uh yeah um that might actually I haven't been
00:31:48.059 working there are no stupid questions here that's okay cool uh you showed us the the markup part of
00:31:54.480 the of the components however if we're going to ensure a visual um Conformity to the design system we're
00:32:01.799 going to need some CSS and yes is there a way to
00:32:07.880 yeah yeah so uh that doesn't conflict whatsoever with everything that was
00:32:13.919 explained today because basically any partial that you're using uh that has
00:32:19.140 markup in it is skinable or uh yeah scannable with CSS as well as uh
00:32:26.279 customizable JavaScript as well so you can have partials uh link to their own
00:32:32.340 uh sorry you don't have to link them actually you can have CSS externally uh
00:32:37.740 based so basically what I would do is in this partial I would give it a class you would give it a CSS class and then in my
00:32:43.860 CSS files I would customize the look of that class that's all you have to do so
00:32:48.899 I usually will do that and and sometimes what I'll do is I'll break my CSS files down by the view components so if I have
00:32:56.159 a view component called accordion I'll have a Javascript file for it called accordion.js and I have a CSS file
00:33:01.740 called accordion CSS they will have only the CSS and JavaScript for that view component so yeah that doesn't conflict
00:33:09.000 whatsoever with using view components in rails way yeah that makes sense thanks
00:33:15.600 uh okay yeah thank you very much everybody uh you can ask me any questions after the talk but that's
00:33:21.120 about it for the talk and Mateo gagne seems to be absent today yeah
00:33:26.519 emergencies we will we won't be able to make it today due to the storm and electricity issues okay well I
00:33:33.299 mean that will give us an extra half hour of networking time so that's pretty good so yeah thank you everybody for
00:33:39.419 attending thank you indeed
00:33:45.980 the CTO around if you have questions about like sub architecture and your
00:33:51.659 stuff we have Wendy's still around yes we're hiring a lexstop we're hiring uh software developers that are
00:33:58.740 intermediate level right and senior level yes
00:34:15.419 you guys have any questions for
Explore all talks recorded at Montreal.rb Meetup
+6