Skip to content

Instantly share code, notes, and snippets.

@Znow
Created November 3, 2011 09:27
Show Gist options
  • Save Znow/1336125 to your computer and use it in GitHub Desktop.
Save Znow/1336125 to your computer and use it in GitHub Desktop.
class CreateJobsUsers < ActiveRecord::Migration
def change
create_table :jobs_users, :id => false do |t|
t.integer :job_id
t.integer :user_id
t.timestamps
end
end
end
<h2>Lediga jobb</h2>
<table width="700">
<tr align="left">
<th>Datum </th>
<th>Arbetsbeskrivning</th>
<th>Ort</th>
<th></th>
</tr>
<% @jobs.each do |job| %>
<tr>
<td><%= job.updated_at.strftime("%d/%m/%Y") %></td>
<td><%= job.name %></td>
<td>Stockholm</td>
<td>
<% if current_user %>
<%= link_to "Apply job", add_job_path(job.id), :method => :put %>
<% end %>
</td>
</tr>
<% end %>
</table>
<br />
class Job < ActiveRecord::Base
has_many :users, :through => :jobs_users
end
class JobsController < InheritedResources::Base
before_filter :authenticate_user!, :except => [:index, :show]
def add_job
user = current_user
if user.update_attributes(:user_id => current_user.id)
redirect_to jobs_path, :notice => "You have now applied for this job."
end
end
end
Yc::Application.routes.draw do
resources :jobs
match "add_job/:id" => "jobs#add_job", :as => "add_job", :via => :put
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users
root :to => "home#index"
end
ActiveRecord::Schema.define(:version => 20111102205359) do
create_table "jobs", :force => true do |t|
t.string "name"
t.string "title"
t.text "content"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "jobs_users", :id => false, :force => true do |t|
t.integer "job_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "fname"
t.string "lname"
t.string "bday", :limit => nil
t.string "address"
t.string "areacode"
t.string "city"
t.string "education"
t.text "info"
t.string "looking_for"
t.string "tele"
t.string "cv_file_name"
t.string "cv_content_type"
t.integer "cv_file_size"
t.datetime "cv_updated_at"
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
t.integer "job_id"
end
end
# encoding: UTF-8
class User < ActiveRecord::Base
has_many :jobs, :through => :jobs_users
devise :database_authenticatable, :registerable, :recoverable, :trackable, :validatable
attr_accessible :email, :password,
:password_confirmation,
:remember_me,
:fname,
:lname,
:bday,
:address,
:areacode,
:city,
:education,
:info,
:looking_for,
:tele,
:cv,
:cv_file_name,
:cv_content_type,
:cv_file_size,
:cv_updated_at
has_attached_file :cv
validates_attachment_size :cv, :less_than => 2.megabytes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment