Tuesday, May 28, 2013

Addressbook App

The current project that I've been working on is the addressbook app to become more familiar with the structure of Ruby. This exercise proved to be effective as it opened my understanding of it. I did have an issue at first on how to display all the entries at once. I eventually got it and was surprised at how simple it was. I grouped all the variables of the class Entry into an array in .erb, which I have never done. I didn't expect to be able to do that in the views folder, but hey I learned something new. I can honestly say that it sucks when I have a problem, but it feels rewarding after solving it. Just like now: I am trying to insert images for each of the variable entries, however it's currently not working.

Sudden realization why I was having issues with inserting images earlier, which is because I was using Rails Ruby rather than Sinatra Ruby. The difference is because the library in rails is not in the Sinatra framework. The "image_tag( )" is something that works in rails and not applicable in Sinatra. Now I'll have to find a way for images to be displayed. Probably similar to my zoo app.

The class exercise "Classercise" we did on the day of this post is to review last week's lesson on "Classes" and how to create objects from them as well "Instance methods" and "Instance variables." By calling the class.new in views and assigning it to a variable. This results in an instance object with the initialize variables that we set. In the initialize method, we set parameters and assign it to the initialize variables (Ex: @title = title). A cool trick to call the initialize variables and have them behave as methods without actually having to write out "def method_name, end" is the "attr_accessor" method. This acts as the setter and getter method and it makes life easier.I think I have more confidence now, but still feel like I only scratched the surface. Somehow, the more I learn, the less I know. Why is that?

No comments:

Post a Comment