Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set custom field when using #create_activity method #288

Open
borisano opened this issue Feb 3, 2017 · 2 comments
Open

Unable to set custom field when using #create_activity method #288

borisano opened this issue Feb 3, 2017 · 2 comments
Labels

Comments

@borisano
Copy link

borisano commented Feb 3, 2017

It is possible to set custom fields using #tracked method, however, when I create an activity using #create_activity method, custom fields are just ignored

def track_activity(model, activity_name, params={})
    model.create_activity activity_name,
                owner: current_user,
                enterprise_id: current_user.enterprise.id,
                params: params
end

I have this method in Application controller and I have added enterprise_id field to database.

@owenstrevor
Copy link

owenstrevor commented Feb 4, 2017

Something similar happened to me where it wouldn't save the activity when I sent a custom field. My fix was to use a different function I found as an answer to another issue.

In this example, my custom field is project_id which is a belongs_to association with the activity. So on creating a new project I added this line:

PublicActivity::Activity.create key: 'project.create', trackable: @project, owner: current_user, project: @project

Quite ugly but am working on a way to clean it syntax.

Btw, @project is here twice as the trackable and the project because it is for creating the project. In all other instances @project will be under the project column not trackable.

@pokonski
Copy link
Member

pokonski commented Jul 20, 2018

You are right that create_activity does not allow passing custom attributes, so it's a potential improvement to be made. @owenstrevor has the right idea about directly creating the model

@pokonski pokonski added the bug label Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants