Hi, I created the ArithmeticDisplayBean class ArithmeticDisplayBean attr_accessor :result end This is the controler class RubyApplicationController < ApplicationController @arithmeticDisplayBean def arithmetic if params[:paramaction] == ''save'' arithmetic = Arithmetic.new arithmeticDisplayBean = ArithmeticDisplayBean.new arithmeticDisplayBean.result arithmetic.add(params[:num1].to_i,params[:num2].to_i) end end end How can I get the result from the arithmeticDisplayBean.result in the view? Can anyone help? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you can use every instance variable you declare in the controller instance in the view. if you define result like this: @result = arithmeticDisplayBean.result the will display it if you write this: <%= @result %> On 27 Jun., 08:01, ayyanar <reachayya...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I created the ArithmeticDisplayBean > > class ArithmeticDisplayBean > attr_accessor :result > end > > This is the controler > > class RubyApplicationController < ApplicationController > @arithmeticDisplayBean > def arithmetic > if params[:paramaction] == ''save'' > arithmetic = Arithmetic.new > arithmeticDisplayBean = ArithmeticDisplayBean.new > > arithmeticDisplayBean.result > arithmetic.add(params[:num1].to_i,params[:num2].to_i) > end > end > end > > How can I get the result from the arithmeticDisplayBean.result in the > view? Can anyone help?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Comments are inline On 6/27/07, ayyanar <reachayyanar-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, > > I created the ArithmeticDisplayBean > > class ArithmeticDisplayBean > attr_accessor :result > end > > This is the controler > > class RubyApplicationController < ApplicationController@arithmeticDisplayBean This is an instance variable of the class, not the instance. It is accessible through class methods, not instance methods. You should be able to remove this line. def arithmetic> if params[:paramaction] == ''save'' > arithmetic = Arithmetic.new > arithmeticDisplayBean = ArithmeticDisplayBean.newThis line arithmeticDisplayBean = ArithmeticDisplayBean.new loads your Bean into a local variable. Local variables are not available in your views. This should be @arithmeticDisplayBean = ArithmeticDisplayBean.new @arithmeticDisplayBean.result > arithmetic.add(params[:num1].to_i,params[:num2].to_i)> end > end > end > > How can I get the result from the arithmeticDisplayBean.result in the > view? Can anyone help?If you use the instance variable then it will be available in your view. Alternatively you can just stick the result into an instance array on the fly @result = arithmeticDisplayBean.result arithmetic.add(params[:num1].to_i,params[> > :num2].to_i)HTH Daniel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---