Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jiaming Zhang](https://uploads.teamtreehouse.com/production/profile-photos/681922/micro_239f015.jpg)
Jiaming Zhang
10,170 PointsIn rails web app, where should I put those structured data related to the view?
Let me be more specific on this. Assume I want to produce a HTML like the following
<div id="btn-group-1">
<button>Button-1a</button>
<button>Button-1b</button>
<button>Button-1c</button>
<button>Button-1d</button>
</div>
<div id="btn-group-2">
<button>Button-2a</button>
<button>Button-2b</button>
</div>
<div id="btn-group-3">
<button>Button-3a</button>
<button>Button-3b</button>
<button>Button-3c</button>
</div>
I want to DRY the code, so I want to store the structure in a array
buttonGroups = []
buttonGroups << {:id => "...", buttons = [....]}
buttonGroups << {:id => "...", buttons = [....]}
buttonGroups << {:id => "...", buttons = [....]}
My question, should I put this part of code in view? Or should I put this in the controller - create a instance variable and pass it to the view? Or should I put them in the model?
1 Answer
![Maciej Czuchnowski](https://uploads.teamtreehouse.com/production/profile-photos/103489/micro_IMG_3403.jpg)
Maciej Czuchnowski
36,441 PointsI would do it in the controller, make an instance variable (or a few of them) and then use .each
structure in the view.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsJiaming Zhang was the answer below helpful? If so, please indicate that by selecting it as Best Answer. If not, please elaborate more so that we could help you further.