views:

73

answers:

2

Hello! On my site, the user can watch his profile. In his profile he can have a look at his data (i.e. signature). Now I want my users being able to edit this data while watching it. So I coded the following in my view:

<div id="profile-signature">
  <p>
    <b>Signature:</b>
    <%=h @user.signature %>
  </p>

  <%= form_remote_tag(:update => "signature",:url => { :action => :update_signature }) %>
  <%= text_area(:signature,:class=>"form-textarea") %>
  <%= submit_tag "Save Signature" %>

</div>

in my user controller, I created a new action update_signature

  def update_signature
    puts 'in function!'
    @user = current_user
    puts @user.login
    puts params[:signature]
    @user.signature = params[:signature]
    @user.save
    puts 'saved'
  end

Now, submitting the form, puts params[:signature] will output: classform-textareasfsffsfs where sfsffsfs is the text I entered. Reloading and my page and output the signature on page (<%=h @user.signature %>), I get: "--- !map:HashWithIndifferentAccess classform-textarea: sfsffsfs "

Why do I get this strange string instead of just sfsffsfs (in this case)? What to do, to update the data (<%=h @user.signature %>) automatic without page reload?

+1  A: 

It looks like your text_area call isn't quite right, looking at the docs it should be like this:

text_area(object_name, method, options = {})

so your css class is being set as the method, instead you should use text_area_tag:

<%= text_area_tag(:signature, @user.signature, :class=>"form-textarea") %>

Then the correct value (the text in the text area) should be submitted as the params you're expecting.

Andrew Nesbitt
+2  A: 

Use text_area_tag for getting the text_area field values . With reloading the page there is a mismatch in the div id it should be signature not profile-signature .

<div id="profile-signature">
  <p>
    <b>Signature:</b>
    <%=h @user.signature %>
  </p>

  <%= form_remote_tag(:update => "signature",:url => { :action => :update_signature }) %>
  <%= text_area(:signature,:class=>"form-textarea") %>
  <%= submit_tag "Save Signature" %>

</div>

Make the following changes

 <div id="signature">
      <p>
        <b>Signature:</b>
        <%=h @user.signature %>
      </p>

      <%= form_remote_tag(:update => "signature",:url => { :action => :update_signature }) %>
      <%= text_area_tag(:signature,:class=>"form-textarea") %>
      <%= submit_tag "Save Signature" %>

    </div>

Hope this helps !

YetAnotherCoder