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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:41:18+00:00 2026-05-22T20:41:18+00:00

I seem to have trouble handling error messages. Here’s my method: def destroy @user

  • 0

I seem to have trouble handling error messages. Here’s my method:

  def destroy
     @user = User.find(current_user)
     @authorization = Authorization.find(params[:id])
     if @user.authorizations.count > 1
       @authorization.destroy
       redirect_to(user_path(current_user))
     else

...


     end
   end

I don’t want a user to delete their last authorization (say, Facebook) because then the user won’t have any authorizations associated with it and the account is lost. I want to send an error message that says why the destroy method fails, but I’m just not sure how. Everything I’ve tried just doesn’t work.

I’ve tried things like @user.errors.add => “error message”

But it just shows up blank. I think my problem is with using render. If I try, for example:

 respond_to do |format|
         @user.errors[:base] << "Sorry, you can't delete your only authorized service."
         format.html render :template => "users/show"
      end

I get a problem because rails starts looking for the partials in users/show inside the authorizations directory for some reason, presumably because I’m calling the authorizations controller from a users view.

Here’s how I display the flash in my views:

 def show_flash
      [:notice, :errors, :alert].collect do |key|
          msg = (flash[key].to_s + " (close)")
          content_tag(:div, (content_tag(:a, msg, :class => "#{key}", :href => "#", :onclick => "$('messages').slideUp(); return false;")), :id => key, :class => "flash_#{key}") unless flash[key].blank?
          end.join
    end

I can get notices to appear just fine.

  • 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-22T20:41:18+00:00Added an answer on May 22, 2026 at 8:41 pm

    So, this seems to be working:

     respond_to do |format|
             format.html {redirect_to(@user, :alert => "Sorry, you can't delete your only authorized service.")}      
     end
    

    But, this does not:

     respond_to do |format|
             format.html {redirect_to(@user, :errors => "Sorry, you can't delete your only authorized service.")}      
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have trouble with getting data from a php array, I've looked
The Eclipselink OSGi bundles seem have trouble working in some OSGi containers, notably Felix,
As I'm extremely new to java, I seem to have trouble grasping some concepts.
I seem to have some trouble overloading opIndexAssign in one of my classes. I
I'd need some help to design a monadic datatype, I seem to have trouble
I have this really simple trouble I can't seem to overcome. I'm trying to
I have a public repository on github that I'm having trouble handling pull requests
I seem to have a problem with this SQL query: SELECT * FROM appts
I seem to have an app on my Dev server that has lots of
I seem to have a problem with getting MVC to fill in my custom

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.