Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Rendering a Partial without having to use "_" in front of the filename?

How do I render a partial without having to supply the "_" in front of the file name? Is there a parameter I can call to not use it?

This problem popped up using RABL and Backbone - using RABL requires me to have a file in my views like "index.json.rabl". But, when I use embed the JSON right on the page load (as is usual with Backbone), I'm required to call the file "_index.json.rabl". These 2 files are the exact same thing, just required to have different names. I'm looking to use just 1 file, "index.json.rabl" and force the render() function to look for that file name, without the "_".

=> EDIT

The standard solutions that people have described below don't work. It's likely a RABL issue then? The below code always goes to the views/countries/_index.json.rabl file.

In my .erb file

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

In my 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
like image 871
bluedevil2k Avatar asked Oct 07 '22 06:10

bluedevil2k


1 Answers

You can render a file by doing the following:

render :file => "filename"
like image 154
Chris Ledet Avatar answered Oct 13 '22 10:10

Chris Ledet