As a learner I have and still looking to find that same solution.
paperclip is a full blown gem. To a student it would be profitable if
anyone who knows how to do it in purely rails, would write a small
example.
Say I have a form that includes submitting to other Models as well.
How do I do that?
jobs/new.html.erb
<% form_for [@job], :html => {:multipart => true } do |f| %>
<%= f.error_messages %>
<dl>
<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.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
studio@safarista.com</span>
</dd>
</dl>
<section class="company">
<h2>Now then, some`ing about your company. What should they know?</
h2>
<dl>
<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>
</dl>
</section><!--.company-->
<%= f.submit 'Step 2: Proceed to preview your ad →' %>
<% end %>
My Models are:
Job
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
Catergory
has_many :jobs
This is still not working, the image does not upload. Why? Please help
in the simple inbuilt Rails. Am using v2.3.8
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment