Hello! I''m recoding a PHP website in Rails. I didn''t have to change to the database at all, since it was well designed with foreign keys etcetera However, I got a weird problem with the default scaffolding code. The list.rhtml has the following lines <% for column in User.content_columns %> <td><%=h user.send(column.name) %></td> <% end %> I get the error: Showing //users/list.rhtml/ where line *#13* raised: | wrong number of arguments (0 for 1) And I don''t know why. | However, if I change the line 13 to (I added a bogus argument): <% for column in User.content_columns %> <td><%=h user.send(column.name,"weird bug?") %></td> <% end %> Is this weird or am I overlooking something? Thanks! Rob
> Summary: I changed <%=h user.send(column.name) %> to <%=h > user.send(column.name,"weird bug?") %> and then it works, i.e. it > doesn''t throw any errors anymore and everything displays correctlyYou have to figure out what column.name is when it errors out. send() calls other methods by name. So, if column.name == ''description'', for instance, then user.send(column.name) is the same as calling user.description. For whatever reason, it seems like you''re calling a method that requires at least 1 argument. Calling user.send(column.name, ''Weird Bug?'') is essentially the same as user.description(''Weird Bug?''). Does that make sense? At any rate, there''s a good reason why I don''t write technical books. Check out the Reflection, ObjectSpace, and Distributed Ruby chapter from Programming Ruby: http://www.rubycentral.com/book/ospace.html. -- rick http://techno-weenie.net
Just to back this issue up, I''ve seen it on at least two occasions when building my current app, always with the default scaffolded list. On 6/24/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Summary: I changed <%=h user.send(column.name <http://column.name>) %> > to <%=h > > user.send(column.name <http://column.name>,"weird bug?") %> and then it > works, i.e. it > > doesn''t throw any errors anymore and everything displays correctly > > You have to figure out what column.name <http://column.name> is when it > errors out. send() > calls other methods by name. So, if column.name <http://column.name> == > ''description'', for > instance, then user.send(column.name <http://column.name>) is the same as > calling > user.description. For whatever reason, it seems like you''re calling a > method that requires at least 1 argument. Calling > user.send(column.name <http://column.name>, ''Weird Bug?'') is essentially > the same as > user.description(''Weird Bug?''). Does that make sense? > > At any rate, there''s a good reason why I don''t write technical books. > Check out the Reflection, ObjectSpace, and Distributed Ruby chapter > from Programming Ruby: http://www.rubycentral.com/book/ospace.html. > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I forgot to add: "However, if I change the line 13 to (I added a bogus argument): <% for column in User.content_columns %> <td><%=h user.send(column.name,"weird bug?") %></td> <% end %> --> then it WORKS Summary: I changed <%=h user.send(column.name) %> to <%=h user.send(column.name,"weird bug?") %> and then it works, i.e. it doesn''t throw any errors anymore and everything displays correctly Cheers, Rob
On Jun 24, 2005, at 8:24 AM, Rick Olson wrote:>> Summary: I changed <%=h user.send(column.name) %> to <%=h >> user.send(column.name,"weird bug?") %> and then it works, i.e. it >> doesn''t throw any errors anymore and everything displays correctly >> > > You have to figure out what column.name is when it errors out. send() > calls other methods by name. So, if column.name == ''description'', for > instance, then user.send(column.name) is the same as calling > user.description. For whatever reason, it seems like you''re calling a > method that requires at least 1 argument. Calling > user.send(column.name, ''Weird Bug?'') is essentially the same as > user.description(''Weird Bug?''). Does that make sense? >I ran into the same problem. In my case, I had a column named "format" which was colliding with an inherited method named format. The solution I used was to rename the column. Kim -- Kim Shrier - principal, Shrier and Deihl - mailto:kim-7lDDVWa6PKfQT0dZR+AlfA@public.gmane.org Remote Unix Network Admin, Security, Internet Software Development Tinker Internet Services - Superior FreeBSD-based Web Hosting http://www.tinker.com/