Rendering partial without using the "_" in front of the file name?

How to edit partial without the need for "_" in front of the file name? Is there a parameter that I can call so as not to use it?

This problem arose using RABL and Backbone. Using RABL requires a file in my views, such as index.json.rabl. But, when I use JSON directly on the page load (as usual with Backbone), I have to call the file "_index.json.rabl". These 2 files are the same, you just need to have different names. I want to use only one file, index.json.rabl, and make the render () function look for that file name without "_".

=> EDIT

The standard solutions described below do not work. This is probably a RABL problem? The code below always refers to the file views / countries / _index.json.rabl.

In my .erb file

countryList.reset(<%=get_json("countries", "index", @countries)%>);

In application_helper.rb file

def get_json(view_path, view_action, object)
    path = view_path + '/' + view_action + ".json"
    return raw(render(path, object: object, :formats => [:rabl]))
end
+5
source share
4 answers

From RailsCast # 322 to RABL :

<div id="articles" data-articles="<%= render(template: "articles/index.json.rabl") %>" >

Start at this point, and then find out what happened. But clearly, that render template: pathis the syntax you want.

+1
source

You can make a file by following these steps:

render :file => "filename"
+2
source

render :template => "file_name"?

+1

:

<%= render :file => 'views_directory/index' %>

views_directory - 8)

OLD:

:

render :partial => "index" 

index.json.rabl _index.json.rabl

0

All Articles