Skip to content

Commit

Permalink
job belongs_to user and add jobs rss
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed May 6, 2011
1 parent bdee07e commit ef315cc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/jobs_controller.rb
@@ -1,5 +1,6 @@
class JobsController < InheritedResources::Base
before_filter :authenticate_user!, :only => [:new, :edit, :created, :update]
respond_to :xml, :only => :index

protected
def collection
Expand Down
1 change: 1 addition & 0 deletions app/models/job.rb
@@ -1,6 +1,7 @@
class Job < ActiveRecord::Base
has_many :job_job_types
has_many :job_types, :through => :job_job_types, :source => :job_type
belongs_to :user

validates_presence_of :title, :company, :country, :state, :city, :description

Expand Down
20 changes: 20 additions & 0 deletions app/views/jobs/index.xml.builder
@@ -0,0 +1,20 @@
xml.instruct!
xml.rss(:version => '2.0') do
xml.channel do
xml.title "jobs on rails-bestpractices.com"
xml.link "http://rails-bestpractices.com/jobs"
xml.description 'Post jobs on rails-bestpractices to find good ruby and rails developers'
xml.language 'en-us'

@jobs.each do |job|
xml.item do
xml.title job.title
xml.description job.description
xml.author job.user.login
xml.pubDate job.created_at
xml.link job_url(job)
xml.guid job_url(job)
end
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20110506134609_add_user_id_to_jobs.rb
@@ -0,0 +1,9 @@
class AddUserIdToJobs < ActiveRecord::Migration
def self.up
add_column :jobs, :user_id, :integer
end

def self.down
remove_column :jobs, :user_id
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110504135729) do
ActiveRecord::Schema.define(:version => 20110506134609) do

create_table "admin_users", :force => true do |t|
t.string "first_name", :default => "", :null => false
Expand Down Expand Up @@ -140,6 +140,7 @@
t.string "apply_email"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end

create_table "notification_settings", :force => true do |t|
Expand Down
1 change: 1 addition & 0 deletions spec/models/job_spec.rb
Expand Up @@ -3,4 +3,5 @@
describe Job do
should_have_many :job_job_types
should_have_many :job_types, :through => :job_job_types, :source => :job_type
should_belong_to :user
end

0 comments on commit ef315cc

Please sign in to comment.