כיצד להריץ קוד בצד השרת בלחיצה על כפתור?

סיכום מבוסס בינה מלאכותית

The discussion revolves around executing server-side code in a Discourse plugin when a button is clicked. Yogesh_Kbizsoft wants to run a scheduled job (e.g., Jobs/Scheduled/test_job.rb) via a button or URL, seeking guidance on triggering server-side code. pfaffman suggests using an Ajax request to an endpoint, referencing the subscription plugin as a model. Yogesh_g clarifies the goal: deleting posts for a user with many posts, where the default delete button fails due to a 503 error. They’ve written a cron job to delete 100 posts every two minutes. pfaffman advises running the task directly in the Rails console instead of creating a plugin. merefield supports this, recommending Rails’ ActiveRecord::Batches for efficient deletion. Yogesh_g admits unfamiliarity with Rails and asks for a command, while pfaffman suggests searching for PostDestroyer. Yogesh_g insists on a plugin due to non-technical clients and potential future scalability issues, emphasizing the need for improvements in Discourse’s default post deletion feature.

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

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