I will try to explain this. If you do the same command from
./script/console “@products = Product.find(:all)”, you will be able to
access this hash by calling each element as @products[1].title or by
other
keys in the hash. Does that make since?
I just found this out myself about 1 Minute ago.
Totally makes sense. Makes things much clearer.
I have one more question though
In the rhtml file you find something like this
<%= link_to ‘Show’, :action => ‘show’, :id => product %>
in a controller you find:
def show @product = Product.find(@params[:id])
end
Everything makes sense. Im just not shure where the @params comes from.
Is this some part of the framework ?
Thanks alot again…
John H. wrote:
I will try to explain this. If you do the same command from
./script/console “@products = Product.find(:all)”, you will be able to
access this hash by calling each element as @products[1].title or by
other
keys in the hash. Does that make since?
The @params would be the parameter’s that you pass with the :id =>
product
or if you pass other params as well. On the other question the only way
that I know how to print a whole array is with the @products.each or
for
product in @products. Hope that helps,
@products is an array of Product objects. In your code you are iterating
through the array and for each Product object you are accessing the
attribute image_url.
@products[“title”] would be trying to access an array with a string as
the index, which doesn’t work (this would work with a hash though).
Jan wrote:
As far as I understand @products should be some kinda hash or array, @products[“title”] or puts @products[:title] which obviously doesnt
work.
I think this would help to understand the whole concept.