rabl

How to add parent attributes inside its children in rabl template (when parent is an array)?

给你一囗甜甜゛ 提交于 2019-12-01 11:59:52
How to add parent attributes inside its children in rabl template? To do something like this: some_root_attr: { attr_a: 'rgtr', parent: [ { attr_1: 'asd', child: { attr_3: 6, attr_from_parent_array_member: 'cvb' } }, { attr_1: 'ert', child: { attr_3: 9, attr_from_parent_array_member: 'erty' } }, ... ] } How to get parent array member inside parent array member's child? object @obj attributes :attr_a child :parents do attributes :attr_1 parent = root_object.dup child :child do attributes :attr_3 node(:attr_from_parent_array_member) { parent.attr_from_parent_array_member } end end NB haven't

How to add parent attributes inside its children in rabl template (when parent is an array)?

北慕城南 提交于 2019-12-01 07:41:16
问题 How to add parent attributes inside its children in rabl template? To do something like this: some_root_attr: { attr_a: 'rgtr', parent: [ { attr_1: 'asd', child: { attr_3: 6, attr_from_parent_array_member: 'cvb' } }, { attr_1: 'ert', child: { attr_3: 9, attr_from_parent_array_member: 'erty' } }, ... ] } How to get parent array member inside parent array member's child? 回答1: object @obj attributes :attr_a child :parents do attributes :attr_1 parent = root_object.dup child :child do attributes

HAML prevents template engines to render anything else than HTML

為{幸葍}努か 提交于 2019-12-01 04:24:43
I am using Jbuilder (and I also tried to use Rabl) to render json. When I try to render the jbuilder template in my application it renders the template within the layouts/application file and returns HTML as JSON (see line 'within layouts/application'): Rides controller on Github Started GET "/random_photo.json" Processing by RidesController#random_photo as JSON >> Rendered rides/random_photo.json.jbuilder within layouts/application (0.3ms) Rendered shared/_banners_in_corners.haml (3.0ms) Rendered shared/_sign_in_and_out.haml (2.0ms) Rendered layouts/_navigation.haml (7.3ms) Completed 200 OK

HAML prevents template engines to render anything else than HTML

▼魔方 西西 提交于 2019-12-01 02:51:09
问题 I am using Jbuilder (and I also tried to use Rabl) to render json. When I try to render the jbuilder template in my application it renders the template within the layouts/application file and returns HTML as JSON (see line 'within layouts/application'): Rides controller on Github Started GET "/random_photo.json" Processing by RidesController#random_photo as JSON >> Rendered rides/random_photo.json.jbuilder within layouts/application (0.3ms) Rendered shared/_banners_in_corners.haml (3.0ms)

Accessing the child instance in a RABL template

巧了我就是萌 提交于 2019-11-30 22:30:28
I have a RABL template as shown below object @user attributes :name child :contacts do # does not work if contact.is_foo? attributes :a1, :a2 else attributes :a3, :a4 end end How do I access the Contact object in the child block of the template? I need to perform some conditional logic on the child instance. You can access the current object by declaring the block parameter. object @user attributes :name child :contacts do |contact| if contact.is_foo? attributes :a1, :a2 else attributes :a3, :a4 end end Old answer I ended up using the root_object method , which returns the data object in a

Removing child root nodes in RABL

人走茶凉 提交于 2019-11-29 05:27:42
问题 I'm trying to render a pretty simple data structure using RABL, but I can't figure out how to remove the child root nodes properly. Here are my two templates. First, the collection index template. collection @groups, :object_root => false attributes :id, :name child :files do extends 'groups/_file' end And next, the file partial template. object @file attributes :id Those two templates end up producing the following JSON: [ { "id":"4f57bf67f85544e620000001", "name":"Some Group", "files":[ {

Rails 4 - How to render JSON regardless of requested format?

一个人想着一个人 提交于 2019-11-28 23:15:39
I'd like a Rails controller (all of them, actually, it's an API) to render JSON always always. I don't want Rails to return "route not found", or try and fail to find an HTML template, or return 406. I just want it to automatically and always render JSON, e.g. from a RABL or JBuilder view. Is this possible? Related questions seem to have answers that have the aforementioned downsides. You can add a before_filter in your controller to set the request format to json : # app/controllers/foos_controller.rb before_action :set_default_response_format protected def set_default_response_format request

How to remove html redirection in devise authenticate_user

一笑奈何 提交于 2019-11-27 11:47:50
问题 I use the devise's authenticate_user! method in a controller. This is working fine when the auth_token provided in the request is the correct one but if the authentication fails, I end up with: curl -XGET 'http://localhost:3000/my_obj?auth_token=wrongtoken' <html><body>You are being <a href="http://localhost:3000/users/sign_in">redirected</a>.</body></html> As I use rabl, what is the best way to have something like {'error' : 'authentication error'} returned intead of the html redirection ?