Skip to content

Instantly share code, notes, and snippets.

View safarista's full-sized avatar

Nelson Kelem safarista

View GitHub Profile
# POST /jobs
# POST /jobs.xml
def create
#ADD THIS LINE
@catergory= Catergory.find(params[:catergory_id])#This is the new line added
#It stores the value retrieved from the select box which displays the available categories to be added
#END ADD
@job = Catergory.jobs.build(params[:job])
class Job < ActiveRecord::Base
belongs_to :catergory
# UPLOAD a file for the logo
def upload
uploaded_io = params[:job][:logo]
File.open(Rails.root.join('public', 'images', uploaded_io.original_filename), 'w') do |file|
file.write(uploaded_io.read)
end
end
ActiveRecord::RecordNotFound in JobsController#create
Couldn't find Catergory without an ID
RAILS_ROOT: /Users/safarista/Sites/jobs
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1597:in `find_from_ids'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:619:in `find'
/Users/safarista/Sites/jobs/app/controllers/jobs_controller.rb:50:in `create'
@safarista
safarista / Error.html
Created December 3, 2010 21:47
this is the one will
Showing /Users/safarista/Sites/Rails3/ilinkoln_blog/app/views/layouts/application.html.erb where line #85 raised:
incompatible character encodings: ASCII-8BIT and UTF-8
Extracted source (around line #85):
82: </li>
83: <li>
84: <%= link_to image_tag("twitter.png"), "http://www.twitter.com/ilinkoln/" %>
85: </li>
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.3)
* actionpack (3.0.3)
* activemodel (3.0.3)
* activerecord (3.0.3)
* activeresource (3.0.3)
* activesupport (3.0.3)
* arel (2.0.6)
* builder (2.1.2)
<p id="notice"><%= notice %></p>
<article class="">
<h1><%= @post.title %></h1>
<h2>
<%= @post.created_at.strftime('%b %d, %Y') %> &bull; By:
<%= link_to "#{@post.user.name}", @user %>
&bull; Category:
@safarista
safarista / Trial-of-device.rb
Created January 3, 2011 23:12
Creating users with a profile that has an address association all at once
########User Models#########
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable; :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
@safarista
safarista / roman.rb
Created February 15, 2011 09:40
Screwing up Peter Cooper's challenge of writing ROMAN numbers for the Copyright Date Auto update
module Roman
ARABIC = {'I': 1, 'V': 5, 'X': 10, 'L': 50,
'C': 100, 'D': 500, 'M': 1000 }
def self.const_missing(name)
digits = [*name.to_s.upcase.chars].reverse.map{|r| ARABIC[r] or super}
digits.map.with_index {|d,i| digits[i.zero? ? i : i-1] > d ? -d : d}.reduce(:+)
end
end
Roman::XLVII #=> 47
@safarista
safarista / rhiaroAtFOWD.rb
Created May 17, 2011 15:44
Tweeting with @rhiaro from The Future of Web Design.
@rhiaro @iLinkoln You should relish the challenge then :p But I know full well you start with the design and work backwards. That's right, BACKWARDS
“@rhiaro: @iLinkoln No, we should develop websites with an eye to cater for everyone. http://t.co/wQ4lRVd http://t.co/H6ma0aw”> take sides
class ApplicationController < ActionController::Base
protect_from_forgery
def current_ability
@current_ability ||= Ability.new(current_member)
end
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = "Access Denied."
redirect_to root_url