[Rails] Re: Ajax with JQuery
Try using the noConflict setting //define function to be executed on document ready var $j = jQuery.noConflict(); $j(function(){ $j("#user_name").validate({ expression: "if (VAL) return true; else return false;", message: "Please enter the Password" }); }); On Jun 2, 8:06 am, Manivannanj Jeganathan wrote: > I have used Ajax link and live validation in index.rhtml > Ajax link requires JavaScript "prototype" and live validation requires > "jquery". > i got "element.dispatchEvent is not a function" on the firebug console > when i used "prototype" and "jquery" in same page index.rhtml > after i removed javascript "prototype" library, i got "Ajax is not > defined" on the firebug console when i clicking ajax link. > how can i use both ajax and jquery in the same page? > Can anybody give me a solution for this? > > For example: > > <%=javascript_include_tag "prototype"%> > <%=javascript_include_tag "jquery"%> > <%= javascript_include_tag 'livevalidation/jquery.validate' %> > <%= javascript_include_tag 'livevalidation/jquery.validation.functions' > %> > <%= stylesheet_link_tag 'livevalidation/jquery.validate' %> > <%= stylesheet_link_tag 'livevalidation/style' %> > > <%=link_to_remote "new user",:url=>{:action=>:a},:update=>"div"%> > > <% form_for(@user) do |f| %> > > <%= f.label :name %> > <%= f.text_field :name %> > > > <%= f.submit "Register"%> > > <% end %> > > jQuery(function(){ > jQuery("#user_name").validate({ > expression: "if (VAL) return true; else return false;", > message: "Please enter the Password" > });}); > > -- > Posted viahttp://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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: DRY (don't repeat yourself) way / Hook to Activerecord o
> God please tell me he did not suggest to use threads in order to add an > argument. > -- > Posted viahttp://www.ruby-forum.com/. Here is a brief discussion on Thread.current used in class variables. http://coderrr.wordpress.com/2008/04/10/lets-stop-polluting-the-threadcurrent-hash/ As there is clearly debate about the robustness of using this method, I offer it only as a suggestion. It has worked for me. --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] rails looking for partial with .erb extension instead of .html.erb
I recently deployed a new version of my application. Unfortunately, I accidentally placed a folder containing two partials in the wrong repository (I had copied them from another application), so when I deployed, they were not included. Once I discovered this, I added this folder and the two partials to the repository, then redeployed. Now, however, the application continues to tell me that the view files are missing: ActionView::TemplateError (Missing template dues/_unpaid.erb in view path app/views:vendor/plugins/railmail/app/views) on line #12 of app/ views/parents/show.html.erb: Line 12 looks like this: <%= render :partial => 'dues/unpaid' if ! @parent.current_pt_org_member? %> I have verified that the dues folder contain _unpaid.html.erb is in the apps/views folder. It appears that it is looking for a .erb file instead of a .html.erb. I deployed with capistrano and am using Passenger. I verified that the correct release was being pointed to by /current and that Passenger had been restarted (I manually touched restart.txt a couple of times just to be sure). If you have any thoughts, I would greatly appreciate the advice. Thanks, Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: DRY (don't repeat yourself) way / Hook to Activerecord object (to store IP address on every object created)
> > > > Makund - it is quite likely that your solution will break when > > > multithreading arrives (as will will loads of other stuff) > You could try using Thread.current in your model when storing your class variable. For example, in your User model, you could have the following methods: def self.ip_address=(ip_address) Thread.current[:ip_address] = ip_address end def self.ip_address Thread.current[:ip_address] end You would set these as part of your authentication process User.ip_address = request.remote_ip Then you might be able to use this in a :before_save filter in your models before_save :set_ip_address def set_ip_address self.ip_address = User.ip_address end --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Needs some help with eager loading issue on a has_many through relationship
Philip/Fred thank you for your thoughts. it never ceases to amaze me how some things manage to fix themselves. After looking into this for a couple of hours over the last two days, I reran the page today, and checking into the development log found that I am now down to 3 queries. The homerooms and classrooms query use large "where id in (..)" statements. I understood them to be inefficient compared to joins, but certainly better then individual calls. No idea why the change, but I appreciate your thoughts and help. best, Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Needs some help with eager loading issue on a has_many through relationship
I am loading about 100 students. There is a single query to get them "select * from students...". Then, it appears that it is doing an individual query for each student, to find that students homeroom, then another for that homeroom's classroom. It is not loading all of the classrooms in a single query, nor the homerooms. So for the 100 students, it does one query for student, 100 queries for homerooms, and 100 queries for classrooms (though some appear to be cached). I thought it should only do 3 queries. Thanks Tom On Dec 3, 9:02 am, Frederick Cheung <[EMAIL PROTECTED]> wrote: > On Dec 3, 1:55 pm, hoenth <[EMAIL PROTECTED]> wrote:> Fred, > > > I appreciate your quick response. > > > I am confused though. I thought the point of includes was to get all > > of the related objects in as few db calls as possible. From the log > > file, it is making individual calls for each classroom and each > > homeroom. So for every student, it finds that student's homeroom with > > one call, then finds that homeroom's classroom with another call. > > When you're onlyloadingone then the joins based stuff doesn't make > much sense. > Were you to load 100 students the current code would load those > students, then in query number 2 load all the homerooms and then the > classrooms in the 3rd one. > > > I supposed it will eventually cache all of the classrooms, but since > > homerooms is a join table, (one record for each student) it won't be > > able to. > > > What about has_one :through in 2.1 is broken? I am running 2.1.2 > > It was just screwed. Looks like it was backported to 2.1.2 though so > you should be ok. > > Fred > > Fred > > > Thanks for your help. > > Tom > > > On Dec 3, 8:23 am, Frederick Cheung <[EMAIL PROTECTED]> > > wrote: > > > > On Dec 2, 10:45 pm, hoenth <[EMAIL PROTECTED]> wrote: > > > > > Any idea why Rails seems to be ignoring the :include? > > > > It's not - that's the way it does includes now, one select per > > > association type (unless it has to fallback to the old joins based > > > code because conditions/order reference the included tables). In > > > addition :include of has_one through was broken in 2.1. > > > > Fred > > > > > Any help would be greatly appreciated. > > > > > Best, > > > > Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Needs some help with eager loading issue on a has_many through relationship
Fred, I appreciate your quick response. I am confused though. I thought the point of includes was to get all of the related objects in as few db calls as possible. From the log file, it is making individual calls for each classroom and each homeroom. So for every student, it finds that student's homeroom with one call, then finds that homeroom's classroom with another call. I supposed it will eventually cache all of the classrooms, but since homerooms is a join table, (one record for each student) it won't be able to. What about has_one :through in 2.1 is broken? I am running 2.1.2 Thanks for your help. Tom On Dec 3, 8:23 am, Frederick Cheung <[EMAIL PROTECTED]> wrote: > On Dec 2, 10:45 pm, hoenth <[EMAIL PROTECTED]> wrote: > > > Any idea why Rails seems to be ignoring the :include? > > It's not - that's the way it does includes now, one select per > association type (unless it has to fallback to the old joins based > code because conditions/order reference the included tables). In > addition :include of has_one through was broken in 2.1. > > Fred > > > > > Any help would be greatly appreciated. > > > Best, > > Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Needs some help with eager loading issue on a has_many through relationship
I have the following: 1. A model called Student, which is an STI sub-class of Person 2. Student has the following associations has_many :homerooms has_many :classrooms, :through => :homerooms has_one :current_classroom, :through => :homerooms, :source => :classroom, :conditions => "classrooms.year = '" + $current_school_year + "'" 3. in the view, i have student.name + "(" + student.current_classroom.grade + ")" I need to list all of the students, along with their classroom names (and teacher, but need to get over this hurdle first), so had the following Find in my index action of student_controller @students = Student.find(:all, :order => 'last_name, first_name', :include => :current_classroom) But in reviewing the log, I see that people, homerooms, and classroom are all derived from separate queries. Student Load (0.00) SELECT * FROM `people` WHERE ( (`people`.`type` = 'Student' ) ) ORDER BY last_name, first_name Homeroom Load (0.002000) SELECT `homerooms`.* FROM `homerooms` WHERE (`homerooms`.student_id = 5122) Homeroom Columns (0.003000) SHOW FIELDS FROM `homerooms` Classroom Columns (0.003000) SHOW FIELDS FROM `classrooms` Classroom Load (0.00) SELECT * FROM `classrooms` WHERE (`classrooms`.`id` = 16) I have also tried the following @students = Student.find(:all, :order => 'last_name, first_name', :include => {:homerooms => :classroom) to no avail. In either case, the page displays fine, with students and classrooms. Any idea why Rails seems to be ignoring the :include? Any help would be greatly appreciated. Best, Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: stuck on a validates_presence_of unless issue
I must have looked at those API docs 10 times and didn't see it. Would have bitten...and all that. Thanks for the quick response Craig. Worked like a charm. Tom On Nov 1, 9:05 am, "Craig Demyanovich" <[EMAIL PROTECTED]> wrote: > On Sat, Nov 1, 2008 at 5:29 AM, hoenth <[EMAIL PROTECTED]> wrote: > > > i have a person object. Persons don't need to have addresses, but if > > they have any address field value, they must have them all. So I have > > something like this: > > > validates_presence_of :street_address, :city, :state, :postal_code > > unless :address_blank? > > Instead of > > unless :address_blank? > > use > > :unless => :address_blank? > > since you need to pass options to validates_presence_of as opposed to > writing a normal conditional. See the API docs for validates_presence_of for > more details if you need them. > > Regards, > Craig --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] stuck on a validates_presence_of unless issue
i have a person object. Persons don't need to have addresses, but if they have any address field value, they must have them all. So I have something like this: validates_presence_of :street_address, :city, :state, :postal_code unless :address_blank? address_blank? checks whether all of the address fields are blank. If I run a test like this, it works: describe "given attributes" do before(:each) do @valid_attributes = { :first_name => "Jonny", :middle_name => "D", :last_name => "Miller", :street_address => "123 This Street", :street_address2 => "Suite 200", :city => "Baltimore", :state => "MD", :postal_code => "23993", :salutation => "Mr.", :home_phone => "373-333-", :cell_phone => "373-444-" } end it "given attributes containing valid address values, address_blank? should return false" do it = Person.new(@valid_attributes) it.address_blank?.should == false end However, if I do the following, it "must have a street_address" do @valid_attributes[:street_address] = "" it = Person.new(@valid_attributes) it.save it.errors.on(:street_address).should == "can't be blank" end I get the following result. 'Person must have a street_address' FAILED expected: "can't be blank", got: nil (using ==) So it appears that :address_blank? in the validates_presence_of is evaluating to true. Can anyone give me an idea of how I can detect why this is so? I apologize in advance if this should be an rspec question, and will take it there if advised as such. best, Tom --~--~-~--~~~---~--~~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---