lundi 28 août 2017

Prevent redirect when calling url_for in a rails app

I'm trying to pass a url string to a view from one of my controller methods, like so:

def index
    @locals = {table_cols: $config['global_fields'],
               table_title: $config['main_page']['table_title'],
               ajax: url_for(action: index_data)}} # HERE
end

index_data is a function in my controller that returns some data in JSON format. However, when I navigate to the index page of my application, the browser simply displays the JSON output of index_data.

I'm assuming calling url_for within index is redirecting that page to index_data - is there a way to prevent this and just have url_for return the string, e.g. '/controller/index_data'?

Thanks

Aucun commentaire:

Enregistrer un commentaire