Ruby on Rails - 对数据库数据进行排序,然后根据排序顺序编辑每行数据
这就是我想要做的:
选择数据库表“applicants”中的所有行,然后根据“points”列降序排序。
从上到下逐一编辑每行的“reservedIn”列。
我正在使用 MySQLServer 5.5,并使用 HeidiSQL。我还使用 Ruby 1.9.2、Rubygems 1.4.2,但无法识别 Ruby on Rails 版本。我在一月份早些时候安装了它。
谢谢你!
更新:
您好!我一直在研究从下面的评论中学到的东西,然后我想出了这个(练习功能,不是最终的)!它应该选择所有申请人,按指定的顺序排序,然后将他们所有的 mName 更改为“X”。这不起作用!怎么了?谁能告诉我吗?
def generateReservations
if !session[:user_id]
redirect_to :controller =>'user', :action=> 'login'
else
@applicants = Applicant.find(:all, :order => "points DESC, sName, fName, mName ")
#respond_to do |applicant|
@applicants.each do
mName = 'X'
end
end
end
Here's what I want to do:
Select all rows in the database table 'applicants' and then sort according to the column 'points' in descending order.
One by one, from top to bottom, edit the 'reservedIn' column of each row.
I'm using MySQLServer 5.5, using with it HeidiSQL. I'm also using Ruby 1.9.2, Rubygems 1.4.2 and I can't identify the Ruby on Rails version. I had it installed earlier this January.
Thank you!
Update:
Hello again! I've been studying what I've learned from the comments below and I came up with this (practice function, not final)! It's supposed to select all applicants, sorted in the order specified, and then change all their mNames into 'X'. It doesn't work! What's wrong? Can anyone tell?
def generateReservations
if !session[:user_id]
redirect_to :controller =>'user', :action=> 'login'
else
@applicants = Applicant.find(:all, :order => "points DESC, sName, fName, mName ")
#respond_to do |applicant|
@applicants.each do
mName = 'X'
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Applicants.order("points DESC")
link_to("Edit", edit_applicant_path(applicant))
我的观点,例如
类似的东西
Applicants.order("points DESC")
link_to("Edit", edit_applicant_path(applicant))
I your view, for example
Something like that