similar to: Customizing errors

Displaying 20 results from an estimated 1000 matches similar to: "Customizing errors"

2006 Jun 08
5
Field names in validators
Hi! Is there a (simple) way to use alternative field names in validation messages? For example, if I have a validator like this one: validates_presence_of :email how can I make it print a message like "E-Mail Address can''t be blank" instead of "Email can''t be blank"? I can override the "can''t be blank" part by using the :message
2009 Nov 26
9
ActionView::TemplateError (can't convert ActiveRecord::Error into String)
I cannot work out why this error is appearing. ActionView::TemplateError (can''t convert ActiveRecord::Error into String) on line #3 of app/views/button/_show_enquiry.html.erb: 1: <h1>Send us a message</h1> 2: <% remote_form_for :enquiry, :url => {:action => ''send_mail''} do | f| %> 3: <%= error_messages_for ''enquiry'',
2007 Dec 05
5
Active Record, Migration, and Translation
Hi, I think the columns and table in migration should be able to have an optional "display_name" set manually. Something like: create_table :people, {display_name => "Personne"} do |t| t.column :first_name :string, :display_name => "Prénom". end Let me explain my point of view: Rails is a framework made to write programs in English. You see it when you
2008 Feb 27
8
ActiveRecord validation messages not I18N-friendly and enforces grammar
ActiveRecord validation messages are currently not I18N-friendly. Specifically, I''m referring to the fact that it enforces a certain grammar, namely the beginning of the message must consist of the field name. For example: validates_presence_of :name, :message => "can''t be blank." ...generates the message "Name can''t be blank". This grammar
2011 Mar 29
18
Rails 3.0.6.rc1
ZOMG HAPPY TUESDAY (UTC-7)!!! <3<3<3<3<3 I am happy to announce that the first release candidate for Rails 3.0.6 has been pushed to rubygems.org. ## Release Candidate: What does it mean? The release candidate is very similar to what we will actually release for version 3.0.6. The reason that we release an RC is so that the community can have a chance to postpone or veto commits
2006 Feb 24
2
Shortcircuit evaluations
This is probably a Ruby questions but since my issue exists in a Rails validation I thought I''d post here. I have the following validator validates_each :thumbnail, :regular do |record, attribute, value| unless value.nil? && value.valid? record.errors.add( attribute,
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model? I''m assuming i need to say @mock_thing = mock_model(Thing) @mock_thing_errors = mock("errors") @mock_thing_errors.should_receive(:full_messages).and_return("An error") @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) Just wanted to check the best practice on this kind of thing and how
2006 Feb 28
1
adding to errors in controller?
def update @product = Product.find(params[:id]) @product.attributes = params[:product] if params[:main_image] image = Image.new params[:main_image] if image.save @product.main_image.destroy if @product.main_image @product.main_image = image else @product.errors.add_to_base(image.errors.full_messages.join(", ")) end end
2006 Feb 22
3
Unit test failure - nil object?
I''m following instructions in the Agile book, page 146 for testing an object update to the database. Here''s my code: def test_update assert_equal "jack@smiths.com", @user.email @user.email = "jack@smiths.org" assert @user.save, @user.errors.full_messages.join("; ") @user.reload assert_equal @user.email,
2011 May 20
3
How to handle non model data in form?
Hey, I got a form which looks like this: - form_for(@article, :html => {:multipart => true}, :url => articles_path) do |f| = errors_for(@article) .field = f.label :text %br = f.text_field :text .field = f.label :author_id %br = f.text_field :author_id .actions = f.submit But since I don''t want anyone to type in an author id I changed it
2007 May 09
1
Custom validation error messages.
Hi all, I have a few questions regarding the error messages which are produced by default. For example, if I have "validates_uniqueness_of" I may get an error message "Surname has already been taken'' What if I want a custom message without prefixing the attribute name? I''ve come across a plugin which allows me to do this: validates_uniqueness_of :name, :message
2012 Sep 25
3
Proposal for a new ActiveModel::Errors structure
There are few issues with the current ActiveModel::Errors class. Firstly, when an error is added to ActiveModel::Errors class via #add method (https://github.com/rails/rails/blob/master/activemodel/lib/active_model/errors.rb#L294) its translation is added. It should not be translated when being added, but only when being read. The second issue is a bit bigger. We''d like to create
2006 Oct 08
9
Organizing tests and mocha expectations
I''m simultaneously getting into using Mocha and RSpec-style tests (courtesy of the simply_bdd plugin) and I''m struggling with some issues while trying to organize my specs/test. Here''s a code example illustrating the problem: context "update cliient invalid data" do include ClientsControllerSpecHelper specify "should render edit form" do
2009 Jun 11
8
before_create return value breaking object.save: rails bug?
I know that usually when people say ''i think i found a bug in rails/ruby'' they''ve done something dumb. I''m wondering if this is the case here, but this does seem like a genuine rails bug to me. In my user model i have a few different before_create callbacks. In one of them, if it happens to return false (just because the last statement in it evaluated to
2007 Apr 30
4
Mocking with Calculated Results
I am setting up an AR mock object and wanted to sanity check it. My intent is to mix this into all my examples and then override/add methods where necessary. Note that I''ve anticipated three cases for find: find with one numeric argument => object find with :all => Array find with anything else => nil This roughly approximates how ActiveRecord::find works in this case
2011 Sep 01
2
Custom ActiveRecord Error Message
I''m generating 3 models on 1 controller and i''m rescuing ActiveRecord::RecordInvalid for validation errors, however 2 of the models have the same attribute called "name", and if there''s an error on that field, I wouldn''t know whether that belongs to model A or model B. What then is the best way of modifying the error message of a validation error
2006 Jan 10
2
Make link_to_remote call redirect current view, not read redirected content
Hello everyone ! I have a link_to_remote which creates a Party from a ContactRequest. The action on the server creates the party, marks the contact request as processed, and then returns a redirect. According to my knowledge of HTTP, that is the correct thing to do. Unfortunately, Prototype is being too clever for me at this time... It follows the redirect, without notifying me. Anybody has
2007 Jul 22
3
Retrieving validation messages without making errors
I would like to inform the users about attribute validation conditions for form fields using title as in <span title= "cannot be blank" >. The simplest way would be to use the validation error messages already defined in the models, but I cannot find any way to retrieve these messages, when no error has been made. The methods I have tried as errors.full_messages only returns the
2006 May 26
4
Using ''validates_inclusion_of'' to validate foreign key
I seem to be missing something trying to use ''validates_inclusion_of'' to validate a foreign key and was hoping some one could piont out my mistake? The problem seems to be that Order.find_all.collect is not returning an array that contains the order_id, if I replace it with a hardcoded array everything works as expected. The model: class OrderItem < ActiveRecord::Base
2009 Aug 01
23
Hi doubt in unit testing
def test_check_for_validity post=County.new(:name=>"myname",:description=>"mydesc") assert post.save end above is the method and when i run unit test it is saying as 1) Failure: test_check_for_validity(CountyTest) [/test/unit/county_test.rb:10]: <false> is not true. what does it say i cannot under stand please help -- Karthik.k Mobile -