@content = Content.find (:all,:order => ‘nameof the column DESC’)
eg
if name of column is “name” @content = Content.find (:all,:order => ‘name DESC’)
Thanks a lot. It worked.
Hi Abhimanyu,
I am implementing the functionality where i have to display the products
details as per user id. I have three tables users table, orders table
and line_items table. The fields are:
users table: id,first_name and so on.
orders table: id, user_id, first_name and so on.
line_items table: id, order_id, product_id, quantity and so on.
Now from these tables i have to display the product_id, quantity… as
per user id. Please tell me how to implement this.
Why don’t you take this discussion off-list, or concentrate it to
fewer but longer post? This sort of ping-pong of short messages is not
really helpful to a wider audience.
I must agree with Peter. First, half of this thread is personal
conversation between Abhi and Ruchita and should be taken off this
list. Second, the Rails-related talk is beginning to look more like
chat. You guys should try using IRC and join #rubyonrails on freenode.
Hi,
I need to select the last row from the database. For that am writing the
code: @sorter = SortingHelper::Sorter.new self, %w(id), params[:id], ‘id’,
‘DESC’
sort_by = params[:sort] @content = Content.find :all, :order => sort_by, :limit => 1
but this coding is returning the value (#).
Can anyone tell me where i am wrong?
Let me clear my reqt once again. I have three tables users, orders and
line_items. Orders table have user_id and line_items have order_id.
Now the following code is giving error:
uninitialized constant UserController::Line_items
def search @orders = Order.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 = Line_items.find_by_order_id(@id) @product << @var
render_text “a”
else
render_text “abc”
end
end
end
end
there are associations between all these tables rt? . also you alsop
want to have all the products of a particular user rt?
please let me know and if possible send the whole error code
@orders = Order.find :all
this is horribly inefficient
@var = Line_items.find_by_order_id(@id)
find_by_x is like a find :first. You probably want find_all_by_x
The class name is LineItem (if you’re adhering to the usual
conventions).
If you’ve defined your relationships properly, you could do something
along the lines of
(eager loading those associations might be a good idea)
You seem to be stumbling over some really basic rails stuff. Find a
good book on rails and read and understand it. AWDWR is a popular
favourite, and there’s a book you can get for free at http://www.sitepoint.com/books/rails1/freebook.php
I have defined all the associations. In line_item model i have defined
belongs_to :order and in order model I have defined belongs_to :user.
The error is:
NameError in UserController#search
uninitialized constant UserController::Line_items
RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
I have defined all the associations. In line_item model i have defined
belongs_to :order and in order model I have defined belongs_to :user.
The error is:
NameError in UserController#search
Like I said before, if you are adhering to the conventions, the class
name is LineItem, not line_item or Line_item or Line_items
I have defined all the associations. In line_item model i have defined
belongs_to :order and in order model I have defined belongs_to :user.
The error is:
NameError in UserController#search
Like I said before, if you are adhering to the conventions, the class
name is LineItem, not line_item or Line_item or Line_items
Fred
Sorry the class name is LineItem.
class LineItem < ActiveRecord::Base
belongs_to :order
end
Even then it is throwing the same error.