Day 37

Sinatra is moving along. Params are definitely an important concept...

Seth

2 minute read

fire and smoke

Sinatra is moving along and clicking well. I have this fear after being somewhat cocky in last night’s post that the spirits of those Senior Devs before me are going to jump into my learning and humble me some. If so, not today. It’s all making sense the first time through. I think this is because there’s very little new logic. It’s just where to put that login in regards to models, views and controllers. Like, if I’m going to use ruby in a webpage the page with be index.erb so it can be interpretted and I’ll have to wrap code in <% %> or <%= %> depending on what I’m going to do with it.

The largest piece of info I learned outside of more of the Sinatra DSL is how params work.

If you are unfamiliar with the params object and how it relates to form and inputs, that’s totally fine. The TL;DR is that all the information the user submitted in the form is available to your code within a hash named params.

So for form data for example, let’s say we have <input name="username" value="" /> and the form has an input box and in that box is withloudhands (I don’t know why the curriculum chose this as an example lol). withloudhands is now the “current value”. Let’s say there’s also an email input which I won’t paint the picture of. The params hash after this is submitted would be {username:"withloudhands", email:"yourcoolemail@gmizzle.com"} and this hash can be used just like any other hash. So params[:username] would return "withloudhands". I did notice that the hash stores everything as strings so when performing math operations I had to utilize the .to_i method.

I also learned that controller actions never care about their return values. This came up when a student suggested using #tap in a lecture and Avi said that while it would work he didn’t think it was the best option. I still haven’t dove into what #tap actually does even though I’ve discussed it with Mike in the past. I did come across a great, and quick read, blog post “Block, yield, tap” by the more studious Rachel Walwood who’s also going through Flatiron right now. She goes through exactly what it is in a solid and concise manner.

Time spent today: 2:19
Time spent total: 152:56
Lessons completed today: 7
Lessons completed total: 372

comments powered by Disqus