How to execute server-side code when clicking a button?

How can I do something like,
When I click on a custom button, I want to run some server side code.

For instance One button click I want to run file Jobs/Secheduled/test_job.rb

Or Can I run the code inside this file when somebody visits the url admin/plugins/my-plugin.

I am a beginner to discourse plugin development, And really struggling to do something like this, Any help will be much appricated

Then you’ll need to make an Ajax request to an endpoint that runs that code.

Can you say more about what you want to happen on the server side?

I want execute the code inside file Jobs/Secheduled/test_job.rb

Or you can say I want to run a cron job.

Can you please show me an example code how can I make ajax request to an endpoint and execute the code inside the file.

You’re still describing your solution and not the problem you’re solving. What do you want to do in that file? There may be a better way to trigger it. Knowing that will also make it easier to suggest something similar.

The subscription plugin adds an endpoint, so you might look at that. You’ll need to add a route in rails and then in ember add an action to your button that will call it.

I have a user with huge number of posts. I want to delete all posts of for that user the default delete all posts button giving 503 error. So I written a code schedule a cron job to run every 2 minutes and delete 100 posts at a time

Just run it at the rails console and don’t write a plugin.


Use the language features and do as @pfaffman suggests. Writing a bespoke front end hook to achieve this is seriously OTT.

See: ActiveRecord::Batches

I am not familiar to rails. Can you show me the command to delete posts for that user

1 Like

You can try searching for PostDestroyer

Yes, you are but there are many such users on the site. And my client is non-technical person how will he that.I need to write a plugin as the client institng me

And also the issue can arises in other forums website. We really need to have a look at the issue I am facing. we can make improvements in default delete post feature in future update

13 posts were merged into an existing topic: I am getting 502 error while trying to delete topics created by specific user