Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render with ActionController #28

Closed
jyr opened this issue Mar 31, 2013 · 4 comments
Closed

Render with ActionController #28

jyr opened this issue Mar 31, 2013 · 4 comments

Comments

@jyr
Copy link

jyr commented Mar 31, 2013

Hi

I tried improve performance app using "ActionController::Metal" in controller like http://newaperio.com/blog/19-fast-json-api-controllers-in-rails but using rabl-rails. I don't know as add the rabl's render

any tips?

Sorry, for posting here.

@ccocchi
Copy link
Owner

ccocchi commented Mar 31, 2013

rabl-rails registers itself to ActionView so you should be able to use it when you use ActionView to render your response. I'd use at least ActionController::Rendering and ActionController::MimesRespond in your controller to use the render keyword. You may have to specify the :format and :handler options when using render

@ccocchi ccocchi closed this as completed Mar 31, 2013
@jyr
Copy link
Author

jyr commented Mar 31, 2013

@ccocchi I have

class ApiPropertiesController < ActionController::Metal
      include ActionController::Rendering
      include ActionController::Renderers::All
      include ActionController::ImplicitRender
      include ActionController::MimeResponds

      respond_to :json

     def agent
         respond_with(@property = Property.joins(:agent).find(params[:api_property_id]))
     end
end

I get

[(135)
    {
        "agent_id": 556,
        "nty_id": null,
        "office_id": 145,
        "property_type_id": 2,
        "title": "4984-RAV DEPTO EN VTA CORPUS CRISTY (Tamaulipas)",
        "updated_at": "2013-03-30T00:10:32Z"
     }
]

do not use my agent.json.rabl template. I want to get

[(135)
    {
        "agent": {id: 556, name: "Luis"},
        "nty_id": null,
        "office_id": {id: 14, name: nil},
        "property_type_id": {id: 2, name: "Casa"},
        "title": "4984-RAV DEPTO EN VTA CORPUS CRISTY (Tamaulipas)",
        "updated_at": "2013-03-30T00:10:32Z"
     }
]

@ccocchi
Copy link
Owner

ccocchi commented Mar 31, 2013

Remove the ActionController::Renderers::All and you will why: no default views path has been set. It must be set by another module you didn't include. You can add append_view_path 'app/views' manually and it will use your template.

@jyr
Copy link
Author

jyr commented Mar 31, 2013

ok, works with

class ApiPropertiesController < ActionController::Metal
  include ActionController::Rendering
  include ActionController::ImplicitRender
  include ActionController::MimeResponds

  append_view_path 'app/views'

  respond_to :json

 def agent
     respond_with(@property = Property.joins(:agent).find(params[:api_property_id]))
 end
end

In my template I have "node(:url) { |property| property_url(property) }" but I get

undefined method `property_url'

I need add another helper of rabl in my controller?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants