I can’t get clean results from database,
module PagesHelper
def list
wishes = WishList.select("content").where("user_id = #{@user.id}")
wishes.each do |wish|
puts wish.fetch_hash
end
end
end
results for user with id 6:
[#<WishList content: "test3">, #<WishList content: "test4">, #<WishList content: "test5">]
but i want to get list like:
test3, test4, test5 without flood, how i can get it ?
First, never ever ever interpolate values into
where. This can lead to SQL injection of parameters. For example, this is bad:And this is OK:
This will automatically escape the
@user.idportion of the query, which there isn’t really a need for in in this query, but imagine you were doing something like this:Then anybody could pass through any value in
params[:admin]they want.So.
Anyway, access it through an association:
Then as Carl Lazlo recommended: