Can''t get this?...I''m close I think, my calculation appears to be working, but.... when i access duration = <%= @enquiry.course_duration %><br> in my final view it''s blank.. course_duration is getting set to null but works for the calculation? controller.. ---------- class EnquiriesController < ApplicationController layout ''welcome'' before_filter :login_required, :except => [:new, :create, :blank] def index list render :action => ''list'' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @enquiries = Enquiry.find(:all, :order => ''created_at ASC'') end def list_by_start_date @enquiries = Enquiry.find(:all, :order => ''requested_start_date ASC'') end def list_not_responded # @enquiries = Enquiry.find(:all, :conditions => ''responded = null'', :order => ''requested_start_date ASC'') # entity = MyEntity.find_all_by_active(true) @enquiries = Enquiry.find_all_by_responded(false) end def show @enquiry = Enquiry.find(params[:id]) end def new @enquiry = Enquiry.new @courses = Course.active_courses @accomodations = Accomodation.active_accomodation # @enquiry.course_booking_fee = Course.registration_fee render :layout => "welcome" end def create @enquiry = Enquiry.new(params[:enquiry]) @courses = Course.active_courses @accomodations = Accomodation.active_accomodation if @enquiry.save @enquiry.set_fixed_fees # set the fixed fees @enquiry.calculate_fees # calculate @enquiry.save flash[:notice] = ''Your enquiry has been sent to Europa School of English. You have received a summary by email. We will contact you shortly with further information.'' # redirect_to :action => ''list'' rmoved rf, we need to go somewhere else after a new enq. redirect_to :action => ''blank'', :id => @enquiry # redirect_to :action => "blank" Notifier.deliver_signup_thanks(@enquiry) else render :action => ''new'' end end def edit @enquiry = Enquiry.find(params[:id]) @courses = Course.find(:all) @accomodations = Accomodation.find(:all) end def update @enquiry = Enquiry.find(params[:id]) if @enquiry.update_attributes(params[:enquiry]) flash[:notice] = ''Enquiry was successfully updated.'' redirect_to :action => ''show'', :id => @enquiry else render :action => ''edit'' end end def destroy Enquiry.find(params[:id]).destroy redirect_to :action => ''list'' end def blank @enquiry = Enquiry.find(params[:id]) end end model ------ class Enquiry < ActiveRecord::Base belongs_to :course belongs_to :accomodation attr_accessor :accomodation_duration, :course_duration # before_validation :set_fixed_fees, :calculate_fees def set_fixed_fees # set accommodation_booking_fee from the Selected Accomodation # set course_booking_fee from the Selected Course self.course_booking_fee = course.registration_fee self.accommodation_booking_fee = accomodation.booking_fee end def calculate_fees # DO STUFF ! # self.blah_fee = blah_duration * whatever self.course_fee = course.price_per_week * course_duration.to_i self.accommodation_fee = accomodation.price_per_week * accomodation_duration.to_i @factor = case @duration_in_weeks when 1..4 1.0 when 5..12 0.9 when 13..24 0.8 when 25..47 0.7 else # from 48 and up 0.5 end self.course_fee = (self.course_fee * @factor) self.total_fee = course_booking_fee + accommodation_booking_fee + course_fee + accommodation_fee end validates_date :date_of_birth, :requested_start_date validates_presence_of :title, :firstname, :surname, :address1, :phone, :country, :nationality, :course_duration, :english_level, :course_id, :accomodation_id, :message => "can''t be blank" validates_format_of :email, :with => RFC2822::EmailAddress end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 31 Aug 2008, at 22:47, bingo bob wrote:> > > Can''t get this?...I''m close I think, my calculation appears to be > working, but.... when i access duration = <%= @enquiry.course_duration > %><br> in my final view it''s blank.. course_duration is getting set to > null but works for the calculation? >Hard to say since you haven''t said what view is involved (top tip - pasting 200 lines of code isn''t the best way to get people to read your question. try to only include the relevant bits). Are you under the impression that course_duration will be save to the database? it won''t (it''s just a regular instance variable rather then an activerecord attribute). Fred> > controller.. > ---------- > > class EnquiriesController < ApplicationController > > layout ''welcome'' > > before_filter :login_required, :except => [:new, :create, :blank] > > def index > list > render :action => ''list'' > end > > # GETs should be safe (see > http://www.w3.org/2001/tag/doc/whenToUseGet.html) > verify :method => :post, :only => [ :destroy, :create, :update ], > :redirect_to => { :action => :list } > > def list > @enquiries = Enquiry.find(:all, :order => ''created_at ASC'') > end > > def list_by_start_date > @enquiries = Enquiry.find(:all, :order => ''requested_start_date > ASC'') > end > > def list_not_responded > # @enquiries = Enquiry.find(:all, :conditions => ''responded = > null'', > :order => ''requested_start_date ASC'') > # entity = MyEntity.find_all_by_active(true) > @enquiries = Enquiry.find_all_by_responded(false) > end > > def show > @enquiry = Enquiry.find(params[:id]) > end > > def new > > > @enquiry = Enquiry.new > @courses = Course.active_courses > @accomodations = Accomodation.active_accomodation > # @enquiry.course_booking_fee = Course.registration_fee > > render :layout => "welcome" > > > end > > def create > @enquiry = Enquiry.new(params[:enquiry]) > > @courses = Course.active_courses > @accomodations = Accomodation.active_accomodation > > if @enquiry.save > > @enquiry.set_fixed_fees # set the fixed fees > @enquiry.calculate_fees # calculate > > @enquiry.save > > flash[:notice] = ''Your enquiry has been sent to Europa School of > English. You have received a summary by email. We will contact you > shortly with further information.'' > # redirect_to :action => ''list'' rmoved rf, we need to go > somewhere > else after a new enq. > > redirect_to :action => ''blank'', :id => @enquiry > > # redirect_to :action => "blank" > Notifier.deliver_signup_thanks(@enquiry) > > else > render :action => ''new'' > > end > > end > > def edit > @enquiry = Enquiry.find(params[:id]) > @courses = Course.find(:all) > @accomodations = Accomodation.find(:all) > > end > > def update > @enquiry = Enquiry.find(params[:id]) > if @enquiry.update_attributes(params[:enquiry]) > flash[:notice] = ''Enquiry was successfully updated.'' > redirect_to :action => ''show'', :id => @enquiry > else > render :action => ''edit'' > end > end > > def destroy > Enquiry.find(params[:id]).destroy > redirect_to :action => ''list'' > end > > def blank > @enquiry = Enquiry.find(params[:id]) > > end > > > end > > > > model > ------ > > > class Enquiry < ActiveRecord::Base > > belongs_to :course > belongs_to :accomodation > > attr_accessor :accomodation_duration, :course_duration > > > # before_validation :set_fixed_fees, :calculate_fees > > def set_fixed_fees > > # set accommodation_booking_fee from the Selected Accomodation > # set course_booking_fee from the Selected Course > > self.course_booking_fee = course.registration_fee > self.accommodation_booking_fee = accomodation.booking_fee > > end > > def calculate_fees > > # DO STUFF ! > # self.blah_fee = blah_duration * whatever > > self.course_fee = course.price_per_week * course_duration.to_i > self.accommodation_fee = accomodation.price_per_week * > accomodation_duration.to_i > > @factor = case @duration_in_weeks > > when 1..4 > 1.0 > when 5..12 > 0.9 > when 13..24 > 0.8 > when 25..47 > 0.7 > else # from 48 and up > 0.5 > end > > self.course_fee = (self.course_fee * @factor) > > self.total_fee = course_booking_fee + accommodation_booking_fee + > course_fee + accommodation_fee > > end > > validates_date :date_of_birth, :requested_start_date > > validates_presence_of :title, > :firstname, > :surname, > :address1, > :phone, > :country, > :nationality, > :course_duration, > :english_level, > :course_id, > :accomodation_id, > :message => "can''t be blank" > > validates_format_of :email, :with => RFC2822::EmailAddress > > end > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry Fred, Noted re the tip... here''s a few lines from the view... <%= @enquiry.course.name %><br> base price per week = <%= @enquiry.course.price_per_week %><br> duration = <%= @enquiry.course_duration %><br> <--- The Line that''s null @enquiry.course_booking_fee : <%= @enquiry.course_booking_fee %><br> and yes, I thought course_duration would be saved, or to put it another way, I''d like it to be? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 1 Sep 2008, at 06:19, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Sorry Fred, > > Noted re the tip... here''s a few lines from the view... > > <%= @enquiry.course.name %><br> > base price per week = <%= @enquiry.course.price_per_week %><br> > duration = <%= @enquiry.course_duration %><br> <--- The Line that''s > null > @enquiry.course_booking_fee : <%= @enquiry.course_booking_fee %><br> > > and yes, I thought course_duration would be saved, or to put it > another > way, I''d like it to be? >Then it needs to be a column on your enquiries table. Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 1 Sep 2008, at 06:19, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> >> and yes, I thought course_duration would be saved, or to put it >> another >> way, I''d like it to be? >> > Then it needs to be a column on your enquiries table. > > FredIt is...that''s why I don''t get it? enquiries contains a column called "course_duration" of type integer. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 1 Sep 2008, at 12:25, bingo bob wrote:> > Frederick Cheung wrote: >> On 1 Sep 2008, at 06:19, bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> wrote: >> >>> >>> and yes, I thought course_duration would be saved, or to put it >>> another >>> way, I''d like it to be? >>> >> Then it needs to be a column on your enquiries table. >> >> Fred > > It is...that''s why I don''t get it? > enquiries contains a column called "course_duration" of type integer.In that case the problem is that you''ve got attr_accessor :course_duration. This is replacing the accessor methods that read/write from the database column with one that don''t (ie just plain old ruby accessor methods backed by an instance variable) Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 1 Sep 2008, at 12:25, bingo bob wrote: > >>> Then it needs to be a column on your enquiries table. >>> >>> Fred >> >> It is...that''s why I don''t get it? >> enquiries contains a column called "course_duration" of type integer. > > In that case the problem is that you''ve got > attr_accessor :course_duration. This is replacing the accessor methods > that read/write from the database column with one that don''t (ie just > plain old ruby accessor methods backed by an instance variable) > > Fredyou got it, thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- maths not working (can't get this)
- prices (where to store them and how)
- monster method (too hard for my skill level)
- ActionView::TemplateError (can't convert ActiveRecord::Error into String)
- [LLVMdev] PyPy sprint announcement: Gothenburg 7th - 11th December 2005