Roy Royal <lists@ruby-forum.com> writes:
> I use this type of code for different message and status in my api.
>
> def 404
> respond_to do |format|
> format.json {render json: { error: '404, not found' }, status: 404}
> format.xml {render xml: { error: '404, not found' }, status: 404}
> end
> end
>
> This works but can I refactoring this code, maybe to one single line?
While I can applaud the desire, I think in this case you should NOT
attempt to simplify that in any way, as it would obfuscate what's going
on. This is clean, terse, and extremely clear what is going on.
If this sort of thing is repeated over and over with different status
codes, *that* should be simplified into a single method, passing in the
code.
--
Tamara Temple
tamouse@gmail.com
http://www.tamouse.org
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/m2y4aiiqll.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment