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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:58:10+00:00 2026-05-27T01:58:10+00:00

I have a few validations for my votership has_many :through model. However, i’m not

  • 0

I have a few validations for my votership has_many :through model. However, i’m not quite sure how to handle validation errors since i’m using create! Here’s my code:

  def cast_vote_up!(user_id, direction)
    voterships.create!(:issue_id => self.id, :user_id   => user_id,
                                             :direction => direction)
  end

this is within my Issue model. I have issues and users and users vote on issues via the join model. How do I handle errors in validations since I am just using create! Usually I would do something like

if @model.save
   #code
else
   #other code
end

but without the .save i’m not sure what to do

  • 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-27T01:58:10+00:00Added an answer on May 27, 2026 at 1:58 am

    create! will throw an error on failure, but if you use create (without the !) you can handle the error the same way you do with save

    if voterships.create(....)
       ...if successfully created...
    else
       ...if create failed...
    end
    

    Using the bang (!) basically means you’re asking your app to cease further execution immediately, if something goes wrong. There are situations where that might be desirable, but when dealing with forms, and user input, you’ll need to use the non-bang version because people often make simple typing mistakes that should be caught and dealt with, rather than showing an application error page.

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

Sidebar

Related Questions

We have quite a few validation methods that need to access repositories / database
I have form with few text boxes which goes through validation (both server and
I have a few classes in my current project where validation of Email/Website addresses
I have few Question for which I am not able to get a proper
I have a few validations happening in the first step of a form. When
I have seen quite a few code samples/plugins that promote uploading assets directly to
I have a few custom form validation rules I wish to apply. Things like
Over a few years, I have have written a few validation classes and have
i have set up a few validation rules and i have a VFpage using
I have a username textbox on a form, that has a few validation rules

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.