similar to: validates_uniqueness w scope

Displaying 20 results from an estimated 4000 matches similar to: "validates_uniqueness w scope"

2006 Jun 14
3
Prevent duplicate HABTM associations
Hi, I am trying to restrict duplicate has_and_belongs_to_many associations. I tried to find support for a association validation for duplicates but couldn''t find anything. I understand I could use :uniq=>true on the model association but this would only prevent it from displaying duplicates, I want to stop duplicate associations being inserted in the first place. I have a vague
2006 Jun 27
4
Not Active Record Model Validation
I have a problem with ruby on rails validation total_book_toy.rhtml ================ <%= text_field ''book1'', ''title1'' %> <%= text_field ''book2'', ''title2'' %> I want to validate these text_field so user can''t insert same title. However, I was stuck how to do it. Or maybe you have another way how to do it.
2006 Jul 18
3
Newbie validation question
I am having problems with a validation, the full model code is below. The validate routine is attempting to see if another record with the same artist_name, title, & catalogue_no exists in the products table. If so, it should throw an error. This is the validation code: def validate if Product.find(:all, :conditions => ["artist_name = ?, title = ?, catalogue_no = ?",
2006 Oct 12
2
How do I test a unique index?
I have a loans table and a payments table. Each loan has_many payments. So far no problem. Now, the payments table has a payment_number field, and each payment has a payment_number unique within that loan. For example, Loan A can have payment_numbers 0, 1, and 2 and Loan B can have payment_numbers 0, 1, 2, and 3 (but only one of each payment_number). I can enforce this with a unique index in
2009 Jul 04
12
save! not allowed after validates_uniqueness
I have this in a model validates_uniqueness_of :aspect, :scope => :user_id In an instance method of the same model I have "save!" but I don''t touch the :aspect attribute in that instance method at all. Whenever that save! command is run however I get this error: ActiveRecord::RecordInvalid: Validation failed: Aspect has already been taken I don''t
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here''s the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number =>
2010 Nov 02
2
Why can I do a case insensitive Validation but not Find?
Why can I do this.... validates_uniqueness_of "username", :case_sensitive=>false .... but not this.... User.where "Xx", :case_sensitive=>false ? -- 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
2008 Aug 21
1
validates_uniqueness_of not working - urgent
I''m using restful_authentication to let users register and login. Lately, however, I''m seeing multiple login and emails being created even though I have validates_uniqueness_of as below: user.rb validates_uniqueness_of :login, :email, :case_sensitive => false mysql> select id, login, email, created_at, state from users;
2006 Jul 26
8
change text_field_tag class
in my booking / _form I have the following input fields : (startdate and endate) <div> <label for="startdate">Booking Start Date</label><br /> <%= text_field_tag(''startdate'', @startdate, {:class => @startdateclass, :readonly => "readonly", :maxlength => "25"} ) %> <%= observe_field("startdate",
2006 Jul 19
2
Creating a safe sequence generator
Hi all, I''ve got a rails and database question. Accounts have jobs, and job numbers should be assigned per account. Account 89 should have jobs 1-whatever, which are not the same as account 67, which has jobs 1-whatever. In the past, I have accomplished this quite easily with: create table job ( accountid int(10) unsigned not null default 0, jobid int(10) unsigned not null
2007 Jun 26
3
what is the :or parameter in a submit_tag ?
I read the following tag in teh Beast example <%= submit_tag''Login'', :or => link_to_function(''forgotten password'', "$(''reset-password'').toggle();") %> I understand the link_to_function, but what is this :or parameter used for ? the link doesn''t appear, so it cannot be used... thanks for your lights kad --
2007 Dec 22
8
Rails 2.0 rescue_from
I am trying to use the new Rails 2.0 macro : rescue_from class PostsController < ApplicationController rescue_from ActiveRecord::RecordNotFound, :with => :deny_access ... def show @post = Post.find_by_id(params[:id]) raise ActiveRecord::RecordNotFound if @post.nil? #illegal access ..... end def deny_access respond_to do |format| format.html end end but the
2009 Mar 23
5
Rspec weird behaviour
Hi, I recently migrated from classic rails testing to Rspec, so I am pretty new to the framework and still learning. I am getting weird errors on an ActiveRecord model test, here is the basic class model definition: class Size < ActiveRecord::Base has_many :quantities, :dependent => :destroy validates_presence_of :name validates_uniqueness_of :name, :case_sensitive => false end
2006 Oct 14
2
sending parameters with link_to_remote Ajax Request
In a panel, I have an hidden input field which is modified by a javascript function (from calendar) how can I sent the value of this input field in my link_to_remote call ? presently I just send back one parameter (an id) but I need both... <input type="hidden" name="booking[start_at]" id="f_date_s" value="booking[start_at]" /> ... <%=
2007 Jun 12
3
REST Routing issue
If I use http://0.0.0.0:3000/users/25/messages/new I can create a new message ressource for user 25 that''s OK.... I would like to be able to use such url : http://0.0.0.0:3000/users/25/messages;send?to=5 in order to create a new message from user 25 for a specific receiver how should write my route ? I tried.... map.resources :users do |users| users.resources :messages,
2008 May 23
20
Rails validation is inefficient
Hi, I have a User model, with a validates_uniqueness_of :login The generated SQL for the validation is: SELECT * FROM `users` WHERE (LOWER(users.login) = ''fernando'' AND users.id <> 10001) LIMIT 1; and it takes 0.13s to happen (my table has 10.000 rows) When I use the EXPLAIN instruction on it, it shows that it will use the primary_key as index, but this is not
2005 Dec 29
3
Verification problems
Hello, Hope this isn''t a newbie question - but I don''t seem to be able to find relevent information elsewhere. I am having trouble getting the following to work: Schema ====== ActiveRecord::Schema.define(:version => 1) do create_table "authors", :force => true do |t| t.column "name", :string end create_table "books", :force =>
2012 Jun 06
3
how to do a Model.order(:name) using a :case_sensitive => false ?
this option is available in validation.. is there any equivalent when doing a query or should it be SQL dependent ( coded in the model ) ? thanks for feedback -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe
2006 Oct 31
3
ActionMailer how to check mail sent
OS X 10.4.8 I am sending an email via Actionmailer settings are written correctly in environment.rb ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.raise_delivery_errors = :true ActionMailer::Base.perform_deliveries = :true ActionMailer::Base.default_charset = "utf-8" ActionMailer::Base.server_settings = { :address => "mail.mydomain.com", :port => 25,
2007 Jan 20
2
find_by_sql with named parameterized sql
I tried to use named parameters in my SQL query , using find_by_sql Order.find_by_sql ([select * from orders where amount > ? and quantity > ?", [ @amount, @quantity ] works;.. but Order.find_by_sql ([select * from orders where amount > :amount and quantity > :quantity ", [ :amount => @amt, :quantity => @qty ] is not working a I wrong or should I use a plain select