Skip to content

Instantly share code, notes, and snippets.

View raysrashmi's full-sized avatar
🏠
Working from home

Rashmi Yadav raysrashmi

🏠
Working from home
View GitHub Profile
sphinx_scope(:ny_ca_and_ma_only) do
{:conditions => {:state => ['MA', 'CA', 'NY']}}
end
define_index do
indexes name, :sortable => true, :infixes => true
indexes nickname, :sortable => true, :infixes => true
indexes city_code
indexes address
indexes state
indexes city, :sortable => true, :infixes => true
set_property :enable_star => 1 # Both are needed to allow stars in search
set_property :min_prefix_len => 1 # Both are needed to allow stars in search
params[:user] = {:name => 'Foo',:email => 'foo@example.com'}
@user = User.new(params[:user])
def user_params
params.require(:user).permit(:name, :email)
end
params[:book].permit(:name,:author,:chapters_attributes => [:number_of_pages])
params.require(:book).permit(:name,:author,:public)
class BooksController < ApplicationController
def create
@book = Book.new(book_params)
respond_to do |format|
if @book.save
format.html { redirect_to @book, notice : 'Book was successfully created.' }
else
format.html { render action : "new" }
end
class Book < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
end
gem 'strong_parameters'
config.active_record.whitelist_attributes = true