Archive | February, 2013

collection_select *THIS*

27 Feb

Spent a good 3 hours today trying to get a simple (?) select box working in a create form. The create form is for ‘pages’ (from the ‘simple_cms’ app developed in the tutorial on Lynda.com) while the select bax needed to display a list of choices from another class. I was hiking on my own here, well of the tutorial map, dressing things up and trying to implement something a little more helpful and interesting.

The code, now that I’ve got it working, is now woefully unassuming:

<tr>
        <th>Subject</th>
        <td><%= collection_select(:page, :subject_id, Subject.all, :id, :name) %></td>
      </tr>

Just some HTML and a bit of embedded Ruby. Certainly nothing to keep a man hunched over his laptop for several hours, right?

I wish!

Where you now see ‘:subject_id’ (so clean and simple) I previously had ‘:id’. That was my first and biggest problem, from which all others henceforth cascaded, in an unrelenting, repentent-less (can I say that?) flow. (I said it.) The Subject object id’s would appear very nicely in the drop-down (by their :name attribute, no less) but never got written to the database and I couldn’t figure out why. So I went a-Googling and a-trying some other helper methods and a-beating various bushes and getting…results, but none of the results I wanted.

Oh, and errors. Lot’s and lot’s of errors, too. Mustn’t forget those.

Then, to make things more confusing, the new data with the missing id caused the ‘list’ view to break which alone took me a fair while to figure out. (see ‘errors’ above)

By the time I did, I was getting pretty good with command-line MySQL. I was also getting pretty good at pulling out fistfulls of my own hair, which is perhaps slightly less valuable on today’s job market. This tutorial uses MySQL, which is kind of cool. SQLite3 is much easier to get going with, but the experience I’ve gained using MySQL this time is much more extensive.

So anyways, that pesky ‘:subject_id’ field was the culprit. ‘subject id’ is the foreign key in the ‘pages’ table I really (and I mean REALLY) wanted to populate. For a long time the drop-down seemed to be working and showing all the desired choice options, but after submitting the form, the relevant field in the database was always, constantly, confoundingly and steadfastly, ruthlessly and forever deeply, cunningly and unforgivably an endlessly echoing cavern of relentless emptiness. (Did I already use ‘relentless’?) Anyways, the Dalai Lama would have been very proud of the formlessness my subject_id’s were displaying.

Thing is, I was calling it by it’s foreign name, ‘:id’ instead of the key name, ‘subject_id’.

Oops. Is that a problem?

And so it was actually working fine the whole time, doing exactly what I was telling it to. Updating the pages.id and not even glancing at the pages.subject_id.

Do you hate that? I know I sure do.

Pick through the rubble at GitHub.

Also, big thanks to the StackOverflow poster who provided this lovely (and I do mean lovely) human-readable-run-down of the ‘collection_select’ helper.

Of buildings and builders…

23 Feb

I’ve been working to apply the Selenium knowledge I’ve learned with Java to Ruby, and it’s going surprisingly well, thanks to the superb design of the WebDriver documentation on the SeleniumHQ site. They give all the specifics in a multi-lingual format which lets you switch easily between Java, Ruby, Python and other languages for almost all of their example code snippets. Very nice.

I’ve decided to focus less on Java and more on the dynamics of simply using Selenium with any language. I really want to learn Ruby and get deeper into Rails. A lot of what I learned earlier is starting to click and to be honest, I dread the thought of doing it all the ‘hard way’ with Java. That said, the familiarity and experience I’ve gained in working with Java as much as I have has been invaluable. Every problem encountered has led to a greater understanding of how software is made, every little victory in understanding and accomplishment has fueled a fire to learn more.

I’ve discovered that I really enjoy building things, even if they are just small things, and that I enjoy getting some real understanding of how the big things are made, even if I may never be suitable candidate for building them myself.

Feeling the fear…

18 Feb

Fear...
“Oh God. I am never going to understand this stuff!”

Got into some deep water this past week in the Udemy.com course on Selenium Testing with Java. The concepts of synchronization are not so difficult, but the actual practice of creating our own customized ExpectedConditions for use with the WebDriverWait class proved quite intimidating. This involves creating either a named class which is then instantiated as the argument for the wait.unti() method, which is where we would normally go straight to the existing ‘ExpectedConditions’ class and it’s stock methods (which usually suffice), or creating more of an ad-hoc ‘inline’ class which more of a one-off ‘disposeable’ approach.

The idea isn’t rocket science, but the coding aspect, for me, has yet to sink in.

So this time, rather than dive into the exciting distraction of Ruby on Rails, I’ve decided to face the beast and dig a little deeper into the Java language and into the deeper aspects of Object Oriented programming itself.

This leads me to a find I came upon recently which has been extremely helpful. There’s a site similar to Udemy which some may know of called Lynda.com which, for a very reasonable monthly fee, has a ton of surprisingly polished and detailed video instruction on all manner of topics related to software and business. The course I’m digesting know is called ‘Foundations of Programming: Object-Oriented Design’. In the course introduction, the instructor nailed something which I had felt but not yet put clearly into words, namely, that there are a lot of programmers (beginning as well as seasoned professionals) who work with object-oriented languages day in and day out, but who don’t fully understand how to use and apply the concepts and capabilities of the paradigm to solve the tasks at hand. He goes on to underline the importance of Analysis, Design and Programming (understanding, planning and building) and then holds up a sheet of paper saying that, “THESE are the tools we should be using as we begin a new project, NOT the editor or IDE”. Even as a student, I’ve felt the rush of opening the IDE and getting something of my own started, only to find later that I’m losing focus and perhaps realizing that I’ve chosen the wrong approach but am already too deeply vested in it to rip everything out and do it over. In a production setting of course this can be deadly.

So there’s a real emphasis on planning here, and I can see by the syllabus that this will be covered deeply in lectures to come. While ‘planning’ doesn’t sound like as much fun at first as ‘coding’, the excitement will come when I get the satisfaction of putting the two together and coming up with something productive!

This discussion leads right into a discussion on software development methodologies and then an increasingly detailed run-down on Objects, Classes, methods, Inheritance, Encapsulation, Polymorphism and so on, explained in terms which even the lay-est of the laymen like me can understand. For a $25 monthly fee, these lectures on Lynda.com are well worth checking out.

As for the Selenium training, I’m going to browse the remaining videos in the syncronization section and then move on, to cookies (and a glass of warm milk perhaps) and javascript, which I’m hoping will entail a return to a more comfortable level of Java programming. I have my work cut out for me, however, and I am determined to fill in the gaps until I can review (and practice) the the advanced synchronization strategies with confidence.

Fear?  Nah!
Herman says: “Feel the fear and code it anyways!”

A Minor Shift on the Rails

9 Feb

The ice has been getting a bit thin on the Rails tutorial and I’ve been feeling like I really need to go back and start it again to reinforce the knowledge I’ve learned so far, and to hopefully fill in some gaps of which there are…many.

I wanted to mention one little thing that finally hit home.

Previously, when I looked at a url (URI, really) for this Rails sample_application like this:

http://localhost:3000/static_pages/home

I wasn’t thinking through what it really meant. I was picturing it in my mind as “a file called home (.html presumably) sitting on a server somewhere in a directory called ‘static_pages’.

But it’s not that at all!

Rather, I’m just now starting to read it like this:

“In the static_pages controller, run the ‘home’ method.” That in turn leads to the home.html.erb view, but the view was in no way being pointed to directly in the way I was at first envisioning. It says as much plain as day in the tutorial, but all those darn trees made it hard for me to see the forest.

It’s actually been a very bad day for Rails for me today. Before deciding to re-do the tutorial, I was trying to follow another, shorter tutorial on creating a blog with Rails. That’s something I’d like to do down the road, moving this blog to a new, similar but different, home on Heroku. I thought that I had perhaps learned enough to make sense of a tutorial that was a little faster and looser than the one I’ve been following.

Au contraire! It only served to illustrate (usefully, if not painfully) how little I really understood of what I’ve done so far. It’s very easy to coast along a tutorial and say, “Yeah, I got that,” and still miss a great deal.

Hey, if I have to ‘lather-rinse-repeat’ twenty times before it sinks in, then that’s what I’ll do.

I’ll have a clean head of hair if nothing else.

More on Sinatra

8 Feb

I completed the Sinatra tutorial and learned a great deal. There’s still so much to sink in, though, but I’m starting to get a better feel for installing gems and really using them. It’s still a little strange to me how requiring a gem in a ruby program then lets me ‘break the rules’ in all sorts of creative ways, such as letting me do a redirect (a Sinatra thing) and including a flash message along with it. Doing the same syntax without first installing the gem and then requiring it in your code will be interpreted as nonsense by Ruby.

No different, really, than configuring a java program to use JUnit or Hamcrest, but there we have the IDE taking care of most of it for us, along with the Maven POM file.

There ain’t no ‘ALT-Enter’ in Ruby or Rails to tell you what you’re missing and give you some handy options as to what to do about it!

Which reminds me that I will be auditioning the JetBrains RubyMine IDE for Ruby and Rails. At this stage of the learning game, however, it may prove more of a distraction than a real help. Still, I love the IntelliJ IDE for my Java exploits and look forward to getting a taste of something similar with Ruby and Rails.

On the flip side, I enjoy using the vi editor as well, and have it configured with syntax highlighting which looks great. My skill set with vi is very basic, though, and it would be nice to really be able to make it fly. That’s going to be a concerted effort all by itself.

Sigh. Onward!

Project Night!

6 Feb

Had a great time last night attending my first Project Night with the Boston Ruby Group. A very nice affair in a space in Downtown Crossing provided by thoughtbot complete with tasty snacks and pizza!

The initial discussion/demo covered a quick rundown of testing with the Capybara gem, which facilitates end-user-like website interactions for testing. It tests the app directly, without driving a browser in the way that Selenium would, but a later discussion with Dan from Launch Academy made it clear that Capybara and Selenium can work well together to drive a browser visually. A lot still has to sink in before I really come to grips with this, but it was great seeing the demo and meeting a lot of folks who work with this stuff day in and day out.

Another thing I learned about which has been very productive for my Ruby (and Rails) learning is the Sinatra gem, which is almost like a mini Rails, letting users create interactive web applications with Ruby. There are some conventions shared with Rails and a similar file layout, but things are much more stripped down and manageable. There’s a great tutorial called Singing With Sinatra which has been a huge help in getting some actual practice creating applications of increasing complexity. As usual, the learning process involves a lot of associated areas of expertise (HTML get/post fundamentals and forms, specifically) that need to be explored and practiced in order to master the basics of what a framework like Sinatra can do. Exhausting at times, but fun!

I’m still doing the Selenium practice with Java as well. Currently working on a section concerning synchronization strategies, which is where a lot of automation ‘gotchas’ can lurk.

“Oh the pain, the pain…”

3 Feb

Oh the pain...

Came back to the Udemy training for Selenium/Java after a full week of Ruby on Rails shenanigans (up through chapter 7 on the tutorial) and found that…whoa! I had to re-learn quite a few things which I thought I had ‘owned’. Chiefly, css matchers stumped me at first and I had to kick my own tail to get back up to speed. Given the added complexity of the Udemy chapter dealing with frames and iframes this was no easy task! I also found some “Huh?” moments with trying to recall how to do things like WebDriverWait…ExpectedCondition… without going back to review older code examles. Suffice to say…I reviewed a lot of older examples!

Nothing like a good Skin Bracer ‘cold slap in the face’ moment to get me back in the groove of selenium.

There’s a Selenium conference here in Boston coming up this summer, so I really need to have a strong grip on the basics.