title: Rails return JSON instead of HTML
body: <p>I have a ruby on rails web app, but I want it to act like a web service and instead of HTML to return JSONs. I want this for all CRUD methods. I want the whole page to be rendered as JSON, so far I only achieved this in Show and Edit for the <code>User</code> variable. But I want the whole page, for all CRUD method to show as JSONs.</p>
  
  <pre><code>    def index
      @users = User.all
  end
  
  
  def show
      @user = User.find(params[:id])
  
      # Render json or not
      render json: @user
  end
  
  
  def new
      @user = User.new
  end
  
  
   def edit
      @user = User.find(params[:id])
  end
  
  
  def create
      @user = User.new(user_params)
  
      if @user.save
          redirect_to @user
      else
          render 'new'
      end
  end
  
  
  def update
      @user = User.find(params[:id])
  
      if @user.update(user_params)
          redirect_to @user
      else
          render 'edit'
      end
  end
  
  
  def destroy
      @user = User.find(params[:id])
      @user.destroy
  
      redirect_to users_path
  end
  </code></pre>
  
  <p>So far I found this <code>render json: @user</code>, but I want the whole page to be rendered as JSON and not just the variable. And every URL, for all CRUD methods.</p>
  
  <p>EDIT: if I add to my <code>routes.rb</code> something like this <code>resources :users, defaults: {format: :json}</code> then I get error message "Missing template users/index, application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}"</p>