I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api
Rails.application.routes.draw do
constraints subdomain: "api" do
scope module: "api" do
""" | |
Django ORM Optimization Tips | |
Caveats: | |
* Only use optimizations that obfuscate the code if you need to. | |
* Not all of these tips are hard and fast rules. | |
* Use your judgement to determine what improvements are appropriate for your code. | |
""" | |
# --------------------------------------------------------------------------- |
I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api
Rails.application.routes.draw do
constraints subdomain: "api" do
scope module: "api" do
# Variant 1 | |
def user_params(type) | |
params.require(type.to_sym).permit(attributes) | |
end | |
# Variant 2 | |
def user_params(type) | |
case type | |
when "user" | |
params.require(:user).permit(user_attributes) |
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
# This shell script is intended to be sourced into your shell. It adds | |
# Default Zenoss server settings. | |
[ -z "$ZENOSS_URL" ] && export ZENOSS_URL="http://localhost:8080" | |
[ -z "$ZENOSS_USERNAME" ] && export ZENOSS_USERNAME="admin" | |
[ -z "$ZENOSS_PASSWORD" ] && export ZENOSS_PASSWORD="zenoss" | |
# Generic call to make Zenoss JSON API calls easier on the shell. | |
zenoss_api () { | |
ROUTER_ENDPOINT=$1 |
#model (idea 100% stolen from ryanb) | |
def author_tokens=(ids) | |
ids.gsub!(/CREATE_(.+?)_END/) do | |
Author.create!(:name => $1).id | |
end | |
self.author_ids = ids.split(",") | |
end | |
# jquery.tokeninput.js |