diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 1bdf7d38..f398459d 100644 --- a/app/controllers/jobs_controller.rb +++ b/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 diff --git a/app/models/job.rb b/app/models/job.rb index 9b52bc0c..c200fa78 100644 --- a/app/models/job.rb +++ b/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 diff --git a/app/views/jobs/index.xml.builder b/app/views/jobs/index.xml.builder new file mode 100644 index 00000000..1852333e --- /dev/null +++ b/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 diff --git a/db/migrate/20110506134609_add_user_id_to_jobs.rb b/db/migrate/20110506134609_add_user_id_to_jobs.rb new file mode 100644 index 00000000..b8d3f43e --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 4abb4b22..dabd5da8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -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| diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 1aa13188..8ffa6f0b 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -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