Alan Red wrote:
<%= rating = Product.connection.select_all("select comment,
seller_rating, advert_rating from ratings ")%>
Since you are just doing a database query and not getting any model
objects, you will get an array of hashes as the result. Each hash will
map the column name from your query to its value.
Your "<%=" then means output this value. When you ask Ruby to print a
hash, it just rubs together keys and values as you are seeing.
Firstly, you have model specific code in your view. If the ratings
table changes, you will need to hunt through your code for things like
this and change them.
If you have a ratings table, then do you not have a Ratings model? Why
use another model (Product) to look up a Rating? It looks like you
actually want your lookup to be:
Much simpler and no SQL.
Then you can go through then printing them out something like this:
<% Rating.find(:all) do |rating| %>
Seller rating: <% rating.seller_rating %><br />
Advert rating: <% rating.advert_rating %><br />
Comment: <% rating.comment %><br />
<% end %>
If you do find yourself needing to run SQL to get some results, decide
what model is best associated with the query and add a method to that
model to get the data. Then elsewhere, you just need to call that
method and use the results.