Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
36,440 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,440 PointsMaciej Czuchnowski
36,440 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.