Dear everyone, I am a outsider trying to learn RoR now, so forgive me if my question sounds silly... There is a bug that tears all my hairs out...must be simple one but I just couldn''t figure it out...please help.. Also, I have find some description of access control lists thing in the ruby on rail website and wonder if there is any place I can find a small application using that so I can download and study the coding? I read the book Agile Programming with Rails and I think what I want to do is very similar to the single table inheritance thing...if anyone knows of any good sample of this please let me know. About the bug: I try to twist the scaffolding thing and login regenerator such that, after one user is login successfully, he will be directed to a user/list/1 page if his user.id is 1, user is controller''s name and list is the action. when someone login (using the login generator) successfully, there will be a def welcome and the script is def welcome redirect_to(:controller => "user", :action => "list", :id => @session[:user].id) end The user_controller.rb is class UserController < ApplicationController before_filter :login_required scaffold :user def list current_user_id = params[:id] @an_user = User.find(current_user_id) end end ------- the list.rhtml is <html> <head> <title>test</test> <body> <h3>Welcome back! </h3> <% @an_user.each do |user| %> <tr> <td><%= user.first_name %></td> </tr> <% end %> <%= link_to "« logout", :controller=>"account", :action=>"logout"%> </body> </head> </html> I keep getting the errors below . what is the meaning of undefinted method ''each'' ? NoMethodError in User#list Showing /user/list.rhtml where line #6 raised: undefined method `each'' for #<User:0xa21d1c0> Extracted source (around line #6): 3: <title>test</test>4: <body>5: <h3>Welcome back! </h3> 6: <% @an_user.each do |user| %>7: <tr>8: <td><%= user.first_name %></td>9: </tr> thank you for any help.. sammy --------------------------------- DO YOU YAHOO!? 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Steven Critchfield
2005-Aug-22 17:16 UTC
Re: newbie question: Anyone can help me about this bug
On Tue, 2005-08-23 at 00:56 +0800, s c wrote:> The user_controller.rb is > class UserController < ApplicationController > before_filter :login_required > scaffold :user > def list > current_user_id = params[:id] > @an_user = User.find(current_user_id)of you pass find an id to fetch for you, you do not receive a list but rather a single object.> <h3>Welcome back! </h3> > <% @an_user.each do |user| %>Since you do not have a list, the each in the above line doesn''t make sense and is the reason for your error message. You should be able to just access the @an_user.first_name directly.> <tr> > <td><%= user.first_name %></td> > </tr> > <% end %> > > <%= link_to "« > logout", :controller=>"account", :action=>"logout"%> > </body> > </head> > </html>-- Steven Critchfield <critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org>