cloudhead / toto

the 10 second blog-engine for hackers
MIT License
1.49k stars 244 forks source link

Problems with embedding Toto in Rails #21

Closed resistorsoftware closed 14 years ago

resistorsoftware commented 14 years ago

Hi,

Using the wiki article contributed by markyl to embed Toto inside a rails app, I am running into the problem whereby toto has a problem parsing the request sent to it. The gist git://gist.github.com/299200.git gist-299200 shows the config.ru I am using.

The exception thrown is:

NoMethodError at /blog You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.split

Ruby /home/foo/.gem/ruby/1.8/gems/toto-0.2.8/lib/toto.rb: in call, line 291

So it seems path is nil at this point and no route is set. The ENV shows path_info is set to /blog.

Is there something that can done in Toto do debug why the route is not being picked up properly as per a default install of toto? I have been unable to figure out this little glitch.

Thanks!

resistorsoftware commented 14 years ago

I changed the :root in my config.ru to be "index" instead of blog. So that works when the url is localhost:9292/blog/ and not localhost:9292/blog which is understandable. Is there a way to ensure the localhost:9292/blog without the trailing slash works too? Also, this technique fails when you try the read-on links... they do not append the /blog into the constructed URL and hence those links do not work out of the box.

In my rhtml template I prepend the hrefs dumping article.path with /blog which produces a working url. That sucks.

Also, in toto's init I check if path.nil? is true before trying to build the route. If it is, I simply set it to '/' and it then works for both /blog and /blog/. Again.. an unecessary hack?.... Anyone else using Toto this way???

ack thpfft...

cloudhead commented 14 years ago

Hey, so I looked into this, and the problem was that path_info was "", when doing a request to /blog, instead of / which was expected. I pushed a fix in v0.3.1, tell me how it goes. Also, note that toto will have no idea that the url is actually /blog, it will see it as /.

resistorsoftware commented 14 years ago

Ok. Thanks for the fix to path_info. Now you're telling me that no matter what the url is set to, http://example.com or http://example.com/blog/ toto will continue to just see '/' for generating links to articles? Is there a way to use url perhaps? Thanks..

cloudhead commented 14 years ago

hehe no, the path will be / for /blog, the url var will always be whatever you set it to in the config, which should be http://example.com/blog/ in this case.

resistorsoftware commented 14 years ago

Ok.. so in the ERB templates... it will be necessary to preface article.path with something. yick.

cloudhead commented 14 years ago

Well, you could also just use article.url, which is effectively a permalink

resistorsoftware commented 14 years ago

MMM.. article.url. Okay. Odd thing about that method is it renders the permalink with a trailing slash, which then raises a 404 exception when you try and venture forth there.

cloudhead commented 14 years ago

Really? the end slash shouldn't pose a problem, in fact path ends the url with a slash too..