zstrad44
zstrad44

Reputation: 41

Adding Attachment to Trello card via ruby-trello gem

I am using the ruby-trello gem, and I am having some difficulty adding an Attachment to a card.

Card created without problems. Checklists added, all good.

When I try to create an attachment with Trello::Attachment::create(url: 'Some URL here') I get an error: TypeError (no implicit conversion of nil into String). Am I missing some required values in the creation or have I got the whole thing wrong?

Upvotes: 0

Views: 290

Answers (1)

Omar Bahareth
Omar Bahareth

Reputation: 906

You can use the add_attachment method in the Card class, with the first parameter being either a file or a URL (like in your case), and the second parameter being an optional name for the attachment.

Here's a working example:

require "trello"

public_key = "x"
member_token = "x"
board_id = "x"

Trello.configure do |config|
  config.developer_public_key = public_key
  config.member_token = member_token
end

board = Trello::Board.find(board_id)
list = board.lists.first
card = list.cards.first

attachment = card.add_attachment("https://google.com", "Link to Google")

Upvotes: 1

Related Questions