ruby on rails - Preventing ActionView::MissingTemplate in a Backend-only (API) application? -


my backend api-only application responding clients restclient::internalservererror: 500 internal server error because of following code ( , there being no templates render ).

def create     @project = project.create(params.require(:project).permit(:name))     @project.update_attributes(key: devise.friendly_token)      respond_to |format|         format.html         format.json { render json: @project }     end end 

current solution:

based on rails guide layouts , rendering, can prevented using render json: @project

source: http://guides.rubyonrails.org/layouts_and_rendering.html

the ask:

but want give client option of format, respond_to block more ideal choice.

is there way combine these use first block not result in 500 error?

thanks kindly.

what should user see if asks html response?

  • if requests should handled js, take out whole respond_to structure.
  • if html should something, must create view return or render (or render nothing: true).
  • if want return better error, remove html part, way user receive 406 not acceptable.

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -