All i want to do is display my joined tables user and products to a view.
my code in site controller looks like this:
def receive_drop
@user = User.find_by_id(session[:user_id])
@user.product << @product1
render products_users.find(:all)
end
i should probably because of the specific nature of receive_drop, have to save products_users.find(:all) to a variable @ps. And then include some kind of a code to the views section. that code would say if the product is dropped render @ps.
my code in views looks like this:
<div id="dropAccept"><%= link_to "My Products", :controller=>"site", :action=>"index" %></div>
<%= drop_receiving_element :dropAccept, :hoverclass=>"hover", :url =>{:controller =>"site", :actio开发者_StackOverflown=>"receive_drop"}%>
now i would just like to know how could i show list of products in my view.
(if i simply write---- puts products_users.find(:all)---- here it says this table doesnt exist --- because of course it is empty in the begining. maybe i should put sth like if nil dont show it--- unfortunately because i am not yet used to the syntax i dont know the right way to put it)
thank you in advance for your ansvers.
You answered your own question. Yes, store results in @ps, and then render in view.
精彩评论