-
-
Save sukima/603026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
end | |
CONTROLLER JOBS | |
# GET /jobs/new | |
# GET /jobs/new.xml | |
def new | |
@job = Job.new | |
@cat = Catergory.find(:all) | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @job } | |
end | |
end | |
# GET /jobs/1/edit | |
def edit | |
@job = Job.find(params[:id]) | |
@cat = Catergory.find(params[:id]) | |
end | |
# POST /jobs | |
# POST /jobs.xml | |
def create | |
#ADD THIS LINE | |
# Do you need this? | |
@catergory= Catergory.find(params[:job][: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 = Job.create(params[:job]) | |
respond_to do |format| | |
if @job.save | |
format.html { redirect_to(@job, :notice => 'Job was successfully created.') } | |
format.xml { render :xml => @job, :status => :created, :location => @job } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @job.errors, :status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment