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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:18:04+00:00 2026-05-24T14:18:04+00:00

Currently I verify that there are no duplicated Members when trying to create a

  • 0

Currently I verify that there are no duplicated Members when trying to create a new Member and add it to a Team.

members_controller.rb

def create
  @team = current_team
  player = Player.find(params[:player_id])
  @member = @team.add_player(player.id)

  respond_to do |format|
     if @member.save
        format.html { redirect_to(@team, :notice => 'Member was successfully added.') }
        format.js { @current_member = @member }
        format.xml  { render :xml => @member, 
        :status => :created, :location => @member } 
     else
        format.html { redirect_to(@team, :notice => 'Member already exists.') }
        format.xml  { render :xml => @member.errors, 
        :status => :unprocessable_entity }
     end
   end
 end

team.rb

def add_player(player_id)
    current_member = members.build(:player_id => player_id)
    current_member
end

I want to add some logic to my add_player method in team.rb that checks various properties of the player that is being added. This action will require multiple failure messages, other than ‘Member already exists.’ How do I do this in the Model layer?

  • 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-24T14:18:05+00:00Added an answer on May 24, 2026 at 2:18 pm

    The controller logic to display all errors from base worked. However, I was not able to add errors from the add_player method as Ben suggested. I instead created separate custom validations as such:

    Team.rb
    
    validate validation_name
    
    def validation_name
      if condition
        errors.add_to_base "Error Message"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a command in mercurial that will list all files currently under source
I am trying to verify the that target exposes a https web service. I
I'm currently trying to verify whether or not, given an unsorted array A of
We are running our continuous builds on Hudson currently with mvn clean verify. That
My UsersControllerTest currently fails because I use verify_recaptcha in UsersController#create. How can I write
I'm currently working on what I would call integration tests. I want to verify
I currently use md5_file() to run through about 15 URLs and verify their MD5
I have some integration tests that hit a webserver and verify certain functionalities. Depending
I currently have an iOS app that allows people to submit content to our
On a project I'm working on, there is an existing messaging system that sends

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.