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 trialDavid Greenstein
6,734 PointsWhat is the params[:title] connected to?
I understand the concept of storing the information provided in the submit box as an instance variable but where do we set params to take in :title.
Later on in the videos we use name in the erb file for title and content keys in the hashes. We do not do that in the show.erb file so I was wondering how params knows to accept a key called title.
1 Answer
Ari Misha
19,323 PointsHiya there! Im pretty sure you're already familiar by now with monkey patching and how Ruby creates methods on the fly and OOPs concept in Ruby. Whenever you create a class , you also define initialize method either by overriding or ruby does it for you behind the scenes. Any attribute starting with @ symbol represents the instance variables. And instance variables can be accessed outside the class as well by any object.
So say a user inputs something in the url as title and you wanna capture it, right? It can be captured with params object. Its a global object which has all kinds of information stored in it. Hence, title key can be accessed with params[:title]. Moreover, if you assign the captured url params to an instance variable in the controller class, it'll be always available to you in the views.
~ Ari