gates gates - 1 month ago 4x
Ruby Question

Is there a way I can have only action without view

In my view, there is a

to a named route like
. 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.



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.