Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:14:43+00:00 2026-06-07T19:14:43+00:00

In Rails 3.0.5 & Ruby 1.9.3, is it possible to define the body of

  • 0

In Rails 3.0.5 & Ruby 1.9.3, is it possible to define the body of an around_save callback inline with the around_save declaration?

That is, I’ve noticed that this case works properly:

around_save :around_save_body
def around_save_body
  puts 'before save'
  yield 
  puts 'after save'
end

[114] pry(main)> a = Activity.find(57)
=> #<Activity id: 57, ... >

[115] pry(main)> a.save
before save
after save
=> true

Whereas if I put the body inline, I get a LocalJumpError:

around_save do |activity|
  puts 'before save'
  yield 
  puts 'after save'
end

[117] pry(main)> a = Activity.find(57)
=> #<Activity id: 57, ... >

[118] pry(main)> a.save
before save
LocalJumpError: no block given (yield)
from /home/maksim/hkn/website/app/models/activity.rb:47:in `block in <class:Activity>'

I tried changing yield to yield activity in the second example, but I got the same result. Is it possible to have my around_save body be inline with the around_save declaration?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:14:45+00:00Added an answer on June 7, 2026 at 7:14 pm

    In this case ActiveRecord will pass a Proc as a second argument, simply do this:

    around_save do |activity, block|
      puts 'before save'
      block.call
      puts 'after save'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does map(&:name) mean in Ruby? Ruby/Ruby on Rails ampersand colon shortcut
Possible Duplicates: Ruby/Ruby on Rails ampersand colon shortcut What does map(&:name) mean in Ruby?
Possible Duplicate: Rails 3.0 & Ruby 1.9.2rc: Rake commands return 'already initialized constant' &
I've just got my first VPS & have set up NGinx, Ruby, Rails &
Using Ruby 1.8.6 & Rails 1.2. Models: Job , JobExtraStop : class JobExtraStop <
I have rails 3.1.0 & ruby 1.9.2 playing around with netzke & extjs4. I
I'm writing a little Rails app & part of that is pulling in a
Rails has a method form_for which takes a &proc that contains the content present
In my Rails App, I have a line that says: <% if user_signed_in? &&
I am running Ruby 1.9.1 & rails 2.3.8. Everything is installed fine as far

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.