I''m basically a Ruby noobie. At the moment I''m having a fair bit of trouble trying to figure out what''s going wrong here (partial template): <% @project = Project.find(@the_id) if current_user.userid == @project.client hidden_field ''messages'', ''recipient'', ''value'' => @project.project_manager else hidden_field ''messages'', ''recipient'', ''value'' => @project.client end %> The current_user.userid method is as follows (from model user.rb): def userid "#{self.id}" end All the values I use there are correct. Say that the current user id is 2, you are the client (which == 2), and the project manager (id) is 3. The form that is output is "hidden_field ''messages'', ''recipient'', ''value'' => @project.client" instead of "hidden_field ''messages'', ''recipient'', ''value'' => @project.client", and it happens every time. Why does it not work? I tried stripping white space from the userid, I even looked for possible string comparison problems, but there is no easy-to-find info online. Please help! -- Posted via http://www.ruby-forum.com/.
Hi Isaac, Isaac Rowntree wrote:> > At the moment I''m having a fair bit of trouble trying to figure out > what''s going wrong here (partial template): > > <%> @project = Project.find(@the_id) > if current_user.userid == @project.client > hidden_field ''messages'', ''recipient'', ''value'' => > @project.project_manager > else > hidden_field ''messages'', ''recipient'', ''value'' => @project.client > end > %>For starters, I''d suggest you do the majority of the above, especially the model access (Project.find) in your controller. Second, even if you decide not to follow the MVC model, your current_user will not be available in the view unless you''re passing it in as a local variable to the partial. If not, you''d need to make it an instance variable. hth, Bill
On 7/12/06, Bill Walton <bill.walton@charter.net> wrote:> > Hi Isaac, > > Isaac Rowntree wrote: > > > > At the moment I''m having a fair bit of trouble trying to figure out > > what''s going wrong here (partial template): > > > > <%> > @project = Project.find(@the_id) > > if current_user.userid == @project.client > > hidden_field ''messages'', ''recipient'', ''value'' => > > @project.project_manager > > else > > hidden_field ''messages'', ''recipient'', ''value'' => @project.client > > end > > %> > > For starters, I''d suggest you do the majority of the above, especially the > model access (Project.find) in your controller. Second, even if you > decide > not to follow the MVC model, your current_user will not be available in > the > view unless you''re passing it in as a local variable to the partial. If > not, you''d need to make it an instance variable. > > hth, > Billwouldn''t current_user be available if it''s a helper method? Like that provided by acts_as_authenticated. _______________________________________________> Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060712/f11fad0f/attachment-0001.html
Yes, I should have done it in the controller (slaps wrist). However, until I got it working I assumed it didn''t matter where it was - I just wanted to figure out why it didn''t work. And no, it still doesn''t work. The following code still fails to compare the two numbers together correctly. current_user.userid returns the value ''2'' @project.client returns the value ''2'' thus @recipient should equal ''3'' however, it equals ''2'' when I output the form (<%= hidden_field ''messages'', ''recipient'', ''value'' => @recipient %>) def reply_message @project = Project.find(@the_id) if current_user.userid == @project.client @recipient = @project.project_manager else @recipient = @project.client end end What''s going wrong here??? -- Posted via http://www.ruby-forum.com/.
On Wednesday, July 12, 2006, at 4:04 AM, Isaac Rowntree wrote:>Yes, I should have done it in the controller (slaps wrist). However, >until I got it working I assumed it didn''t matter where it was - I just >wanted to figure out why it didn''t work. And no, it still doesn''t work. >The following code still fails to compare the two numbers together >correctly. > >current_user.userid returns the value ''2'' >@project.client returns the value ''2'' >thus @recipient should equal ''3'' > >however, it equals ''2'' when I output the form (<%= hidden_field >''messages'', ''recipient'', ''value'' => @recipient %>) > > def reply_message > @project = Project.find(@the_id) > if current_user.userid == @project.client > @recipient = @project.project_manager > else > @recipient = @project.client > end > end > >What''s going wrong here??? > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsWhat is probably happening here is that you are comparing a string "2" to an integer (2). "2" == 2 #=> false _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
That''s what I thought, and that''s basically what I said in my original post. However, I looked everywhere but couldn''t find any indication on how to cast to an integer. I know how to cast to a string (to_s), but yeah...> What is probably happening here is that you are comparing a string "2" > to an integer (2). > > "2" == 2 #=> false-- Posted via http://www.ruby-forum.com/.
On Wednesday, July 12, 2006, at 4:27 AM, Isaac Rowntree wrote:>That''s what I thought, and that''s basically what I said in my original >post. However, I looked everywhere but couldn''t find any indication on >how to cast to an integer. I know how to cast to a string (to_s), but >yeah... > >> What is probably happening here is that you are comparing a string "2" >> to an integer (2). >> >> "2" == 2 #=> false > > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails"2".to_i => 2 _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.