Having problems rendering my database entries on a html page

Hi guys, i have been learning clojure for the last four months now (this is my first serious attempt at programming), right now i am following @seancorfield advice
“ClojureScript stuff and just start with a very simple Ring app, then add Hiccup for HTML generation (or Selmer, my preference), then add Compojure or Bidi for routing, then maybe add next.jdbc to work with a database. Take things one step at a time, understanding each step as you go.”
so this past week i have tried building a guest-book application, i started with building the server, then added routing with compojure, then used selmer for HTML generation. All this have worked fine until i wanted to add database functionality. i have setup my database spec and some functions to perform necessary operation (I’m using h2 for database and next.jdbc library).
Here is a snapshot project.clj, database and views.clj files

Going to the url on my browser i get this

Instead of something similar to this

So guys what am i doing wrong/ what haven’t i learnt correctly.

Here is my index.html page

It helps to consider each link in the chain between what you see and the database. Start at one end and try to rule out that it’s an issue, then go one more link in until you hit the connection that’s a problem (or discover the bug.)

I’d start with the DB connection. Instead of pulling out specific fields from the message items, can you print the whole item to verify that you’re getting them in the shape your template expects?

This is good advice for debugging the problem – one step at a time – it’s often very helpful to put println calls into your code to see what the data actually looks like at each place. Displaying {{item}} in your template will probably also be helpful, since that will show what keys are available and their values.

Since you are seeing three Created bullets, that tells you that messages has three entries in it – so you’re getting expected amount of data but the three fields you are trying to display are not present with those names (so you’re getting nil which Selmer renders as an empty string).

It might help you at this point to work through the Getting Started guide for next.jdbc in a REPL session to see what the data looks like.

Trying the above gave me the right output

It looks like your data has keys like :GUEST_BOOK/MESSAGE rather than :message. Do the references to item fields in your template need to be adjusted from item.message to something like item.GUEST_BOOK/MESSAGE?

Thanks guys, i have been able to solve it

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.