Skip to content

Instantly share code, notes, and snippets.

@zackperdue
Created November 24, 2013 20:00
Show Gist options
  • Save zackperdue/7631681 to your computer and use it in GitHub Desktop.
Save zackperdue/7631681 to your computer and use it in GitHub Desktop.
ActiveModel::ForbiddenAttributesError in BlueprintsController#create
Controller:
class BlueprintsController < ApplicationController
protect_from_forgery with: :exception
def index
@blueprints = Blueprint
end
def show
@blueprint = Blueprint.find params[:id]
end
def create
@blueprint = Blueprint.create! params
end
def new
end
private
def blueprint_params
params.require(:blueprint).permit(:name, :body)
end
end
----------------------------------
view:
.container
.row
.col-md-9
%form{action: blueprints_path, :method => "POST"}
%input{:type => "hidden", name: request_forgery_protection_token.to_s, value: form_authenticity_token}/
.form-group
%label{:for => "blueprint-title"} Template Name
%input.form-control{type: "text", name: "blueprint[name]"}/
.form-group
%label{:for => "body"} Template Body
%textarea.form-control{:name => "blueprint[body]", :rows => 30}
%button.btn.btn-success{type: "submit"} Save
.col-md-3
---------------------------------
class Blueprint
include Mongoid::Document
validates_presence_of :name, :body
field :name, type: String
field :body, type: String
# has_and_belongs_to_many :placeholders
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment