# Add new action in rails controller

**URL:** https://meta.discourse.org/t/add-new-action-in-rails-controller/298157
**Category:** Development
**Tags:** plugin-api
**Created:** [March 6, 2024, 10:21am UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157 "2024-03-06T10:21:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![maaatt](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@maaatt](https://meta.discourse.org/u/maaatt)
#### Post date: [March 6, 2024, 10:21am UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/1 "2024-03-06T10:21:56Z")

</div>

I’m building a plugin to add new exports in the users section.  
Instead to add new controller for every export I would like to extend the ExportCsvController and add new actions to it.  
How can I achieve this?

Thanks

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 6, 2024, 1:13pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/2 "2024-03-06T13:13:27Z")

</div>

What problem my are you solving? Could the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin solve it?

If not, you can have a look at it, as it adds a route and exports csv.

---

<div class="post-metadata">

### Author: ![maaatt](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@maaatt](https://meta.discourse.org/u/maaatt)
#### Post date: [March 6, 2024, 1:40pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/3 "2024-03-06T13:40:28Z")

</div>

Thanks for your reply.

I need to create two new exports:

1. users with membership groups
2. categories with related groups

I would like to add these two exports inside the ExportCsvController without creating new controller for every export.  
Yes, the [data explorer](https://meta.discourse.org/t/32566?silent=true) could solve the problem but the client for whom I am building the forum is not technical so exporting to CSV is the only way to show him the data.

The plugin is not adding a new method for an existing rails controller but it is creating a new controller for the [data explorer](https://meta.discourse.org/t/32566?silent=true) logic.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 6, 2024, 2:38pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/4 "2024-03-06T14:38:19Z")

</div>

The [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin will let them download a csv.

And if you want you can automate it by downloading the file directly with the API.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 6, 2024, 2:39pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/5 "2024-03-06T14:39:08Z")

</div>

> [@maaatt](#):
>
> so exporting to CSV is the only way to show him the data

With the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin, you have a button to export in CVS or JSON (and, recently, even one to show a graph).

* * *

You can also allow specific groups to access the query (if we are not talking about admin users here)

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/2/7/4270599c7d9a6047a254d5e326531663206f8343.png)

Then, the user can see a Reports on the group page. He can run the query, and then he can export the results to CSV.

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/b/b/5bbaefd4c5b739708ebb217720a79ed86caeb695.png)

Would that work?

---

<div class="post-metadata">

### Author: ![maaatt](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@maaatt](https://meta.discourse.org/u/maaatt)
#### Post date: [March 6, 2024, 2:55pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/6 "2024-03-06T14:55:55Z")

</div>

Yes it can work but the user need to know how to write down a SQL query right?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 6, 2024, 3:02pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/7 "2024-03-06T15:02:47Z")

</div>

You (the admin) create the SQL, and the user can run the query – the users can’t create or edit.

What the user sees is a list of queries they can run:

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/c/6/ac699878f8883ef03c9669e54d380b80c398e8f0.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/e/b/4eb8c3448f575937e04b119bf4acc4df83702e65.png)

---

<div class="post-metadata">

### Author: ![maaatt](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@maaatt](https://meta.discourse.org/u/maaatt)
#### Post date: [March 6, 2024, 3:05pm UTC](https://meta.discourse.org/t/add-new-action-in-rails-controller/298157/8 "2024-03-06T15:05:54Z")

</div>

Ok thanks, I will try to investigate if this solution can work for our customers. 🙏
