Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
6 total  XML / RSS feed 

sample of dutch validation error messages

//Dutch validation error messages
//Put this at the end of environment.rb

module ActiveRecord
  class Errors
    begin
      @@default_error_messages = {
        :empty => "dient verplicht ingevuld te worden",
        :blank => "dient verplicht ingevuld te worden",
      }
    end
  end
end

Show Errors in PHP

php_flag display_errors on
php_value error_reporting 7

Is this error in installing rails via rubygems important?

Horatio:~ Rahul$ sudo gem install rails --include-dependencies
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.0.0
Successfully installed rake-0.6.2
Successfully installed activesupport-1.2.5
Successfully installed activerecord-1.13.2
Successfully installed actionpack-1.11.2
Successfully installed actionmailer-1.1.5
Successfully installed actionwebservice-1.0.0
Installing RDoc documentation for rake-0.6.2...

lib/rake.rb:733:18: unexpected token: '#'
Installing RDoc documentation for activesupport-1.2.5...
Installing RDoc documentation for activerecord-1.13.2...
Installing RDoc documentation for actionpack-1.11.2...

lib/action_controller/code_generation.rb:77:31: unexpected token: '#'

lib/action_controller/code_generation.rb:168:31: unexpected token: '#'
ERROR:  While executing gem ... (NoMethodError)
    undefined method `find_module_named' for nil:NilClass

suppressing NoMethodError when receiver is nil, within a block

Often in rails you'll do things like

<%= @post.author.name %>


but it may be that you have no post, or the post has no author, and even if that's ok, the above would raise. I came up with a solution that lets you do the following:

<%= ifnil("no author"){ @post.author.name } %>


If at any point the receiver is nil (either @post or #author), execution of the block is stopped and the default value is returned ("no author" in this case, but defaults to nil)

NoMethodError is still raised if you send an invalid message to a non-nil receiver.

Here's the code for ifnil

def ifnil(value=nil)
  yield
  rescue NoMethodError
  raise unless $!.message =~ /:NilClass$/
  value
end

Typo current error

NoMethodError in Admin/content#new 
undefined method `text_filter=' for #
app/controllers/admin/content_controller.rb:24:in `new'
Show framework trace 
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:1200:in `method_missing'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/rescue.rb:80:in `perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `process'
/usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/dispatcher.rb:32:in `dispatch'
/home/rsimplicio/web/public/typo/dispatch.fcgi:20
/home/rsimplicio/web/public/typo/dispatch.fcgi:18:in `each_cgi'
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in `each'
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.6.1/./fcgi.rb:597:in `each_cgi'
/home/rsimplicio/web/public/typo/dispatch.fcgi:18
    
Request
Parameters: None

Show session dump

--- 
:user: !ruby/object:User 
  attributes: 
    name: Robert
    id: "1"
    password: <snipped for security reasons>
    login: Robert
    email: 
:return_to: 
flash: !ruby/hash:ActionController::Flash::FlashHash {}
Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Howto Send Email When Rails Throws An Exception

Add the following to your application.rb:

  protected  

  def log_error(exception) 
    super(exception)

    begin
      ErrorMailer.deliver_snapshot(
        exception, 
        clean_backtrace(exception), 
        @session.instance_variable_get("@data"), 
        @params, 
        @request.env)
    rescue => e
      logger.error(e)
    end
  end


Taken from http://wiki.rubyonrails.com/rails/show/HowtoSendEmailWhenRailsThrowsAnException
« Newer Snippets
Older Snippets »
6 total  XML / RSS feed