How do I add new item to a multiple select field in Airtable? - airtable

Is there an easy way to add new options to the multiple select field in Airtables? Right now when I create a new record with new Multiple Select field entries I get the error
{
error: 'INVALID_MULTIPLE_CHOICE_OPTIONS',
message: 'Unknown choice values: Agency',
statusCode: 422 }
base('Clients').create({
Name: 'Test',
Tag: ['Agency']
}

Related

STRIPE : This customer has no attached payment source or default payment method. RUBY ON RAILS

I've got some issues, i'm trying to implement subscription with stripe > it works when there is for exemple 3 items in my order > it create a subscription for the 3 items.
The problem is that if the customer wants to stop sub only for ONE element, i dont know how to handle this ...
So i was wondering to create a subscription for each element, this is my code
customer = Stripe::Customer.create
#order.line_items.each do |line_item|
product = Stripe::Product.create(
{
name: line_item.product.name,
metadata: {
product_id: line_item.product.id,
line_item_id: line_item.id
}
}
)
price = Stripe::Price.create(
{
product: product.id,
unit_amount: line_item.product.price_cents,
currency: 'eur',
recurring: {
interval: 'month'
}
}
)
Stripe::Subscription.create({
customer: customer.id,
items: [
{price: price.id, quantity: line_item.quantity}
]
})
but i got this error This customer has no attached payment source or default payment method.
and i dont know how to attach it, even with documentation..
any help please ? thank you
As said in comments; To fix the error in the title:
You need to first have the "payment method", if you haven't already, create one:
Maybe using Stripe.js and it's elements API.
Which nowadays has "payment" element, allowing users to choose their payment-method.
And supports Setup-Intent's "client_secret" (beside Payment-Intent's), submittable using confirmSetup(...) method.
Then (using Stripe API):
Attach said "payment method" to the Customer:
(Optionally) set it as their default for invoices (with invoice_settings.default_payment_method).
And, while creating the subscription, pass the customer (that which you atteched said "payment method" to).

Automatically remove associated records if not present in update params

We're using Rails 5.2.2.1 as an API with Vue for the frontend.
A Post has_many :tags. A Post also accepts_nested_attributes_for :tags, allow_destroy: true.
When creating a post, you create the tags at the same time and this works well. When editing tags, however, I'm running into an issue where tags that aren't present in the update payload are not deleted from the database. Here's an example of what I'd expect:
# A Post has currently tags with ID 1, 2, and 3.
# This (pseudo) update payload is sent
{
tags_attributes: [
{
id: 1,
name: 'Tech'
},
{
id: 3,
name: 'Sports'
},
{
id: nil,
name: 'Science'
}
]
}
# The post's tag with an ID of 2 is not present in the update payload, so it should be automatically removed
# Since we're also passing up a new tag without an ID, this tag should be created
I have a solution involving _destroy: '1', but it would be preferable for tags to be automatically marked for destruction based on their presence in the update payload.

receive Array of hashes in API call rails

I 'm working on rails app in which I need to receive array of hashes in API call with Grape like.
{
tournament_id:1
match_id: 10
[
{
team_id: 1
score: 10
},
{
team_id: 2
score: 20
}
]
}
so that I can receive score of each team in single call for a specific match and tournament instead of multiple calls for score of each team.
I have tried multiple things like
group :teams_with_scores, type: Array, desc: "An array of Teams with scores" do
requires :team_id, type: String,desc: "Team ID"
requires :score, type: String,desc: "Score"
end
But don't have a clue that how to do it.
You can send this data as a json string, and then parse this json when you get it:
params do
scores_info, type: String, desc: 'the scores info'
end
get do
scores_info = JSON.parse(params[:scores_info])
end

mongoid update not updating existing fields

After research, I found this link which shows you can update a field dynamically in mongoid:
Model#rename
Performs MongoDB's $rename modifier that renames a field atomically.
MONGOID
person.rename(:bday, :dob)
MONGODB COMMAND
collections["people"].update( { "_id" : ... }, { "$rename" : {
"bday" : "dob" } } )
According to this stackoverflow post, when the fourth paraemeter is set to true, it should update all your records. But it is not working. When I do the following:
Contact.rename('apple info', 'new_info', false, true)
And then query mongodb:
db.mongoid_container_contacts.find()
{ "_id" : ObjectId("558c50256d6163b255060000"), "apple info" : "etretrytr", ...
As you can see, 'apple info' remains in the existing records. Why isn't the name of the existing records being updated?
There is no Contact.rename method in Mongoid4, that method seems to have gone away in Mongoid3. If you want to rename a field in Mongoid3+, you want to call rename on a query:
Contact.all.rename('apple info' => 'new_info')

Symfony 1.3 and forms: the password changes when i click on 'Save', why?

i have installed sfDoctrineGuardUser and have created this model that
inherits sfGuardUser model:
Usuario:
inheritance:
extends: sfGuardUser
type: simple
columns:
nombre_apellidos: string(60)
sexo: boolean
fecha_nac: date
provincia: string(60)
localidad: string(255)
email_address: string(255)
avatar: string(255)
avatar_mensajes: string(255)
I have also created a module called 'miembros' based on that model.
Well, I log normally through sfGuardAuth/signin, then i go to
"miembros/edit/id/$id_of_the_member_i_used_to_log_in" and push 'Save'
button. Then i logout.
If i try to log in again, it says: "The username and/or password is
invalid".
Later, i have realized that when click 'Save' the value of the field 'password' changes (well its encrypted version). So that is the reason why i can not then log in.
But, why the value of the password change when i click on 'Save' ???
Regards
Javi
The sf_guard_user object isn't intended to be extended like this via inheritance. A mechanism is provided to let you link a "profile" object to a user. I have seen people use a method similar to yours, but haven't tried it myself, so not sure if this is a common issue with doing that. But I'd check that all your model and form classes properly inherit each other, including the Pluginxxxx classes from the plugin folder.
Did you display the old password in the password form field ? in this case it could be displayed encrypted and thus encrypted a second time on saving.
Hashes are typically not decypherable, so you should not display the password on a field.
This is a common problem when working with sfGuard. Here are 2 solutions, there is probably others that will answer this issue :
Do not let user changer user's password in this form and create a separate form for password reset
Let password form field empty by default, and save it only when the user types in a new password
I usually get into the second way, here is the form class used :
class ewaSfGuardUserForm extends sfGuardUserForm
{
public function configure()
{
// parent::configure();
//"virtual" new password fields, empty by default
$this->widgetSchema['new_password'] = new sfWidgetFormInputPassword();
$this->widgetSchema['new_password_bis'] = new sfWidgetFormInputPassword();
$error_messages = array('min_length' => 'Passwords must be at least 4 characters long.');
$this->validatorSchema['new_password'] = new sfValidatorString(array('required' => false, 'min_length' => 4), $error_messages);
$this->validatorSchema['new_password_bis'] = new sfValidatorString(array('required' => false, 'min_length' => 4), $error_messages);
$error_messages = array('invalid' => 'New password didn\'t match confirmation');
//validate identical password
$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('new_password', '==', 'new_password_bis', array(), $error_messages));
$this->validatorSchema->setPostValidator(
new sfValidatorAnd(array(
new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('email_address'))),
new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('username')), array('invalid' => 'Email is already in use for another account')),
new sfValidatorSchemaCompare('new_password', '==', 'new_password_bis', array(), $error_messages)
))
);
//unused fields
unset(
$this['groups_list'],
$this['permissions_list'],
$this['password'],
$this['created_at'],
$this['updated_at'],
$this['last_login'],
$this['salt'],
$this['algorithm']
);
//putting back validator for real password field
$this->validatorSchema['password'] = new sfValidatorPass();
}
}
The other part is in action class sf_guard_userActions
protected function processForm(sfWebRequest $request, sfForm $form)
{
$requestParams = $request->getParameter($form->getName());
$requestParams['password'] = $requestParams['new_password'];
$requestParams['email_address'] = $requestParams['username'];
$form->bind($requestParams, $request->getFiles($form->getName()));
if ($form->isValid())
{
[....] Copy of generated code
}
}
The specificity of my implementation is it always force uses email == username.
I do not use an extended model for storing user's profile, but I override defaut sfGuardUser doctrine table to add extra fields like first name, last name, etc. It works this way, perhaps doctrine inheritance would have been better.

Resources