Created
September 29, 2010 15:55
-
-
Save safarista/603003 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 | |
@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]) | |
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 | |
VIEW NEW | |
<% form_for [@catergory, Job.new], :html => {:multipart => true } do |f| %> | |
<%= f.error_messages %> | |
<dt><%= f.label "title" %></dt> | |
<dd> | |
<%= f.text_field :title %> | |
<br> | |
<span class="hint">"Senior Ruby Developer" or "HTML5 CSS3 Guru"</span> | |
</dd> | |
<dt><%= f.label "Location" %></dt> | |
<dd> | |
<%= f.text_field :location %> | |
<br> | |
<span class="hint">"Lincoln, UK", "Tallinn, Estonia", or "Anywhere"</span> | |
</dd> | |
<dt>Category</dt> | |
<% Catergory.find(:all).each do |category| %> | |
<dd> | |
<label><%= f.radio_button :catergory_id, category.id %> <%= category.name.titleize %></label> | |
</dd> | |
<% end -%> | |
<dt class="tarea"><%= f.label "Job descripton" %></dt> | |
<dd class="tarea"><%= f.text_area :description, :size => "70x20" %></dd> | |
<dt class="tarea"><%= f.label "How you should apply" %></dt> | |
<dd class="tarea"> | |
<%= f.text_area :apply, :size => "70x6" %> | |
<br> | |
<span class="hint">Example: Send your portfolio to [email protected]</span> | |
</dd> | |
<h2>Now then, someing about your company. What should they know?</h2> | |
<dt><%= f.label "Name" %></dt> | |
<dd> | |
<%= f.text_field :company %> | |
<br> | |
<span class="hint">Example: 'Safarista Design', 'Safrista Jobs' or '37signals'</span> | |
</dd> | |
<dt><%= f.label :logo %></dt> | |
<dd> | |
<%= f.file_field("upload") %> | |
<br> | |
<span class="hint"> | |
Optional → Your company logo will appear at the top of youur listing. | |
<br> | |
190px wide is optimal. If larger we will resize it automatically. | |
</span> | |
</dd> | |
<dt><%= f.label :url %></dt> | |
<dd> | |
<%= f.text_field :url %> | |
<br> | |
<span class="hint"> | |
Ex: http://www.safarista.com | |
</span> | |
</dd> | |
<dt><%= f.label :email %></dt> | |
<dd> | |
<%= f.text_field :email %> | |
<br> | |
<span class="hint"> | |
This is where we will send you a confirmation receipt of your payment and listing. | |
</span> | |
</dd> | |
</section><!--.company--> | |
<%= f.submit 'Step 2: Proceed to preview your ad →' %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VIEW NEW
<% form_for [@catergory, Job.new], :html => {:multipart => true } do |f| %>
<%= f.error_messages %>
"Senior Ruby Developer" or "HTML5 CSS3 Guru"
Now then, some`ing about your company. What should they know?
Example: 'Safarista Design', 'Safrista Jobs' or '37signals'
<% end %>