Search code examples
ruby-on-railsrubytrello

How to add members to trello board? (using rails app)


I'm using ruby trello gem for my rails app. I need to add members to the created trello board. How can this be realized? I create board like this:

board = Trello::Board.create(
    name: BOARD_NAME,
    description: BOARD_DESC
  )

Solution

  • This answer assumes you are using the ruby-trello gem at version 2.2.0.

    First, instantiate your board. We will use your example here, but you could also find an existing board:

    board = Trello::Board.create(
        name: BOARD_NAME,
        description: BOARD_DESC
      )
    

    Second, instantiate a member. You will need to provide id_or_username for this part:

    member = Trello::Member.find(id_or_username)
    

    Third, add the member to the board. You can use any of :admin, :normal, or :observer depending on the permissions the user should have:

    board.add_member(member, :normal)
    

    This operation does not require a separate call to save as it does not modify the fields of the board; it calls the API directly.