On 13 Nov 2007, at 12:31, Ruchita S. wrote:
solution for that?
Yes. create the association.
Fred
On 13 Nov 2007, at 12:31, Ruchita S. wrote:
solution for that?
Yes. create the association.
Fred
Frederick C. wrote:
On 13 Nov 2007, at 12:31, Ruchita S. wrote:
solution for that?
Yes. create the association.Fred
But how? I dont have a user_id in lineitems table.
No not needed
can you plese check whether the values are coming correct. Also try
running by deleting one by one
eg firt delete @var = Line_items.find_by_order_id(@id)
@product << @var
and run check if there is error
On 13 Nov 2007, at 12:36, Ruchita S. wrote:
Frederick C. wrote:
On 13 Nov 2007, at 12:31, Ruchita S. wrote:
solution for that?
Yes. create the association.Fred
But how? I dont have a user_id in lineitems table.
Read up on has_many :through
Fred
you have to give like
@var = LineItem.find_by_order_id(@id)
Abhi M. wrote:
No not needed
can you plese check whether the values are coming correct. Also try
running by deleting one by one
eg firt delete @var = Line_items.find_by_order_id(@id)
@product << @var
and run check if there is error
The code is:
@orders = Order.find :all
@lineitems = Lineitem.find :all
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
@users = User.find(:all, :conditions => [“first_name LIKE ?”,
“%#{session[:query]}%”], :order => “first_name ASC”)
@product=Array.new
@users.each do |user|
@orders.each do |order|
if user.id == order.user_id
@id = order.id
@var = @lineitems.find_by_order_id(@id)
@product << @var
render_text “a”
else
render_text “abc”
Now the error is:
undefined method `find_by_order_id’ for #Array:0x470c9a8
Abhi M. wrote:
you have to give like
@var = LineItem.find_by_order_id(@id)
Yeah i have given it. But now the value of product is coming #.
@orders = Order.find :all
@lineitems = Lineitem.find :all
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
@users = User.find(:all, :conditions => [“first_name LIKE ?”,
“%#{session[:query]}%”], :order => “first_name ASC”)
@product=Array.new
@users.each do |user|
@orders.each do |order|
if user.id == order.user_id
@id = order.id
@var = @lineitems.find_by_order_id(@id)
breakpoint @var
@product << @var
render_text “a”
else
render_text “abc”
Give breakpoint like this and check bvalue of @var also before that
replace
@product=Array.new with @product=Array.new()
did you check the table entries?
Abhi M. wrote:
@orders = Order.find :all
@lineitems = Lineitem.find :all
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
@users = User.find(:all, :conditions => [“first_name LIKE ?”,
“%#{session[:query]}%”], :order => “first_name ASC”)
@product=Array.new
@users.each do |user|
@orders.each do |order|
if user.id == order.user_id
@id = order.id
@var = @lineitems.find_by_order_id(@id)
breakpoint @var
@product << @var
render_text “a”
else
render_text “abc”Give breakpoint like this and check bvalue of @var also before that
replace
@product=Array.new with @product=Array.new()
Hi,
I have checked the values. Value of @id=order.id… here the value of
id is coming right. I have checked the log file as well. @var =
@lineitems.find_by_order_id(@id)… the query is also coming right in
log file. . i.e.SELECT * FROM lineitems WHERE (lineitems.order_id
=
1),but again the value of @var is coming #
let me confirm once again
1)you changed @var = @lineitems.find_by_order_id(@id) to
@var = LineItem.find_by_order_id(@id)
2)there is a field in LineItem called order_id
3)the association between LineItem and Order is clearly defined
rt?
if yes
Give
breakpoint LineItem.find_by_order_id(@id)
and tell
Abhi M. wrote:
did you check the table entries?
yes i did check the entries.
I am not getting what
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
is as I havent used such code any way I assume it as correct one
Abhi M. wrote:
I am not getting what
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
is as I havent used such code any way I assume it as correct one
I have implemented the textbox to search the user by user name and then
displaying the products as per user id. So this code is to search the
user.
one min user name is unique? or not?
Abhi M. wrote:
one min user name is unique? or not?
please check this code… am not able to find why its not working.
@orders = Order.find :all
@lineitems = Lineitem.find :all
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
@users = User.find(:all, :conditions => [“first_name LIKE ?”,
“%#{session[:query]}%”], :order => “first_name ASC”)
#@product=Array.new
#@product = @users.collect {|u|
u.orders.collect(&:line_items)}.flatten
@product=Array.new()
@users.each do |user|
@orders.each do |order|
if user.id == order.user_id
@id = order.id
breakpoint Lineitem.find_by_order_id(@id)
#@var = Lineitem.find_by_order_id(@id)
#breakpoint @var
@product << @var
render_text @product
else
render_text “andnddjhg”
Abhi M. wrote:
did you check value at breakpoint Lineitem.find_by_order_id(@id)
whenever i give the breakpoint… my website get hanged and i am not
able to view the results.
Moreover the user names are not unique.
the website get hang because you have given breakpoint
you can check values from console
let ur project folder’s name be product let its location be c:
then in console
give like
c:\product\ruby script breakpointer
then run program and come to console
and you can see the value
then type exit there
did you check value at breakpoint Lineitem.find_by_order_id(@id)
check that and let me know I am abt to leave
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs