The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

a problem with the v.story in chapter 7

Hi. I have been playing with PHP and JavaScript for some time now and wanted to try ROR. So far the whole thing has been a breeze. I then hit a small glitch which I need to eradicate before continuing...

I bought Patrick Lenz's book and have followed the instructions rigorously (spotted an error in printed RHTML) and have reached chapter 7 - Ajax and Web 2.0 (p-192), whereupon I have discovered that the v.story call doesn't work; it simply sends back an error:

I have decided to have another go to see if I can replicate the error. I have found that migrating is awkward when you start again from scratch and no databases. But I have persevered and will try again this weekend. I'll get v.story to behave.

OK. That was sorted out. I started from scratch again and was almost successful. v.story isn't a problem any more. However, I cannot preview either index.rhtml (without a refresh) and show.rhtml is broken (not visibly, and I even retraced steps to see whether I missed anything). The output from the browser says:

Not surprisingly, it fails a bunch of tests saying is expects 'x' and observed 'y'. I have absolutely no idea why. I have spent two days going over the whole thing and have drawn blanks everywhere. The files I used are identical to the downloadable versions from the rails book section of the sitepoint site.

I feel that not being able top log out of the shovell app is a symptom of some deep rooted malevolence within the code I have created, even when I have compared it to the code downloads, found it to be exact and have checked the database thoroughly. I must be missing something really simple here.

For the most part, RoR is incredibly straightforward, but when you get a curve ball as a noob, it can be as daunting as learning C# if you're a Masai warrior! I don't know C#.

Thanks samsm, the line in the file gets the score of votes for the class '@story' and displays them in a page with a path called 'permalink' i.e. 0.0.0:3000/story/show/permalink. I have traced back the votes class, story class and permalink class and can see nothing in error having compared them line for line with the downloaded source files.

I have studied the story_controller file from top to bottom and can not determine anything wrong, even though the test results come back with failures for deprecation, they disappear if I change another aspect of the application.

I am going to go back to the end of chapter 6 and work from that point again.

I do not have a protected fetch_stories part in my story_controller yet, so that isn't the answer. Thanks anyway.

I decided to hold off doing the whole thing again and tried a few things that I knew were going to fail. However, the results were not as expected.

It seems that the 'find_by :permalink' query is in fact looking for the name instead. I changed the permalinks throughout to camel case and did a little browsing. The ONLY permalink that works is a single word permalink and name, so changing them all to camel case seemed to be an option. However, it is still loading up my+shiny+weblog (or failing in its attempt to) instead of myShinyWeblog.

That said and posted, I still cannot fathom what the problem is as my experience in coding has been more of a grab, study, edit approach as opposed to a create from scratch one (with the exception of html and css).

Now I'm even more confused!!!

Checking and re-checking is all very well and good but I have discovered a small discrepancy which could be the answer to the issue. The dynamic link in the index.rhtml that randomly changes depending on refresh seems to have a tendency to put a '+' symbol between the words in the permalinks instead of a '-'. It may do that anyway, but it follows that when looking for 'sample-permalink' it is finding 'sample+permalink' and therefor cannot complete the function.

Now it gets really confusing (for me at least). If I change the '+' to a '-' in the address bar, it returns the same error, which is incidentally the self same error as I listed previously.

This may seem like a really stupid question but, do I have to populate all of the permalink fields in the database? There is only one populated at the moment and when I change the '+' to '-' on that one it works a treat.

I am going for a long walk in the woods to look at something else for a change.

So what's the specific problem now? How do you want the application to work? How is it working now? What specifically needs to change?

Does find_by :permalink need to work differently?
Does the state of your development database need to change? (if so, just scrap it, start over)

Isolate your problem. If you take three steps back, any problem in any application is incredibly complicated. get really close to a problem, and the cause is likely simple.

For example, in post #9, the problem was that @story was nil. Once you learn (through the view) that @story isn't being properly loaded with a Story, go back to the place where that should be happening until you can identify specifically why.

Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

Thanks samsm. Sage words you write. I think that as I am new to a thing, I am scared to look at the obvious and disregard it as irrelevant when sometimes, that is the correct approach.

The problem was not with the @story. I figured that out as it broke before the @story class was called. It was trying to get information for :vote and I had somehow loused up something in that part. That was what was throwing out the errors and stuff. I have indeed scrapped it and started over.

I think that until I fully grasp all of the tenets thus far, I should get to a certain point in the book + 1 and then start again from scratch. That way, I should be able to accomplish the preliminary stages with my eyes shut within two weeks.

Being half way through the book is fine but it is nowhere near half way through the process and I have so much more that I need to learn before I begin playing with new, more complicated models. some of which have yet to be done online. I have aspirations and the keenest students sometimes ask the dumbest questions, even if they know the answer; they just need a nudge to let them know that they already know it.