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

Does the fact that Rails have an MVC approach mean that is has dependency
I have a Rails app that sets a cookie and does a redirect to
I'm working with an older version of Rails and ActiveRecord that does not have
I have a Rails application that has to co-exist with a very old legacy
Is this more concise way of writing this: current_user.products.where(:product_id => product.id).present? Does rails have
Does anyone have an example of setting up Authlogic with a namespace in Rails?
Does ASP.NET MVC have anything like the RESTful out-of-the-box features like Ruby on Rails
Does rails have a way to get JUST the src of an image as
Does Rails 3 have an equivalent to MVC3 Areas? I think I came across
Does Rails 3 have anything akin to slices in Merb, or areas in Django

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.