0

I have two fields in my edit page 1.domainName 2.logo When I click on submit button, selected picture and domain name should update the table I tried the below, but its not updating the database.

<%= form_for(@company, :multipart => true) do |form| %> 
<table style="height: 400px; border: 5px; margin-left: 20px; ">
<tr>
        <td width="40%">
          <%= form.label :domain_name ,"Domain Name"%>
        </td>
        <td>
          <%= form.text_field :domain_name %><%= form.submit "Add Domain" %>
        </td>
  </tr>
<tr>
         <td>
            <%= form.label :company_logo,"Company Logo" %>
         </td>
          <td>
              <%= form.file_field :company_logo %>
          </td>
  </tr>
  </table>

In controller
def update
    @company=Company.find_by_company_id(params[:id])
    if @company.update_attributes(params[:company]) then
      render :text=>"Company Details updated successfully"
    end
end
1
  • is there any reason to save image in blob? Commented Sep 11, 2012 at 14:04

1 Answer 1

1

is there any reason to save image in blob? you can use paperclip or carrierwave gem to upload a file.

May be it's not updating blob because it requires raw data and it's may be tempfile try this

company_logo_blob = params[:company][:company_logo].read #or params[:company][:company_logo].tempfile.read    

@company.update_attributes(:domain_name =>params[:company],:company_logo=>company_logo_blob)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. It worked. Almost I spent 4 hours on this. Thanks alot
As Image file takes more memory, I choose blob type. There is no other reason. Sorry for the late reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.