Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way I can have only action without view

In my view, there is a link_to to a named route like random_path. So when the user clicks on that link, it will go to a particular controller with an action, in which I am writing to a DB. It really does not need to render the view. But having the view template seems to be mandatory. Is there a way to avoid having the view.

<%= link_to bla_path do %>

<% end %>

in routes.rb

get 'bla' => 'contr#act'

In controller

in cont_controller.rb

def act 

Model.create(name: "bla")

# I don't need the view for this. 

end 
like image 830
gates Avatar asked Dec 31 '25 05:12

gates


1 Answers

The way http protocol works is that you have to respond to each request. However, you can respond with a blank message, in rails the easiest way to do this is to add:

head :ok

anywhere in your action.

like image 82
BroiSatse Avatar answered Jan 01 '26 22:01

BroiSatse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!