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 3443348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:46:49+00:00 2026-05-18T08:46:49+00:00

Does rails have a break statement? I’m writing a controller that has some pretty

  • 0

Does rails have a break statement?

I’m writing a controller that has some pretty complicated IF statements. In Sum what I’d like to do is something like this:

IF !All these variable exist and are not nil?
BREAK and don’t continue bec something went wrong
END

If XXX = ‘adsasd
do all this stuff
ELSE IF

ELSE
send out an error email

Is a break possible?

  • 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-05-18T08:46:49+00:00Added an answer on May 18, 2026 at 8:46 am

    I don’t know when all of your variables become available, but when I want to do checks in the controller, I usually use the before_filter callbacks to do that. For example:

    class YourController
      before_filter :check_if_variables_exist
    
      def show
        #prepare for render view
      end
    
    private
      def check_if_variables_exist
        unless @your_variable.nil?
          #Do what you want
          render :nothing => true
        end
      end
    

    What this does is that when a request comes to action show in YourController, it will first call the private method check_if_variables_exist. If @your_variable is nil than it will end up at render :nothing => true and the filter_chain will be halted and the action show will never be called. If however your_variable is not nil, then the method will end without doing anything and the controller will then call the action show like usual.

    So all the things you want to check beforehand can be placed in different before_filter callbacks. And if you don’t want the check for all actions in the Controller, it can be specified like this:

    class YourController
      before_filter :first_check,  :only => [:index, :show]
      before_filter :second_check, :only => [:show, :edit]
    

    In my opinion, this is the “rails” way to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access xml that is located in another web server. Does rails/ruby
does ruby on rails have an Admin section generation feature like django?
This is a complicated question with many possible answers, so I'll break down my
Hi guys i have a model livestream which has two columns in the database,
I have a model that requires loading external data from an auxiliary source. A
i have a variable like /projects/3/blah blah or /projects/3 or just /projects What I'd
I have the RedCloth gem in my vendor/gems directory. I also have this in
We are developing a new rails application and are considering moving to Rails 3.
Single Table Inheritance using ActiveRecord. Since we can use @test = Employee.all and find
I came across this messaging tutorial recently, and was intrigued by the use of

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.