0

In my ruby on rails app, I am trying to allow a user to change a field on the screen and as a result, update the database.

A user is promoted with the following screen:

<td id="sb_user-<%=server.id%>" ondblclick="changeUser(<%= server.id %>);"><%= server.sb_user %></td>

enter image description here

When they double click on the sb_user field, a javascript function is called and changes the field to a textbox with a simple go button:

    <script type="text/javascript">
        function changeUser(id) {
            //Stop the auto refresh until user hits enter
            clearInterval(refreshInterval);
            $("#sb_user-"+id).html("<form name='user'><div class='input-append'><input name='user_input' class='span1' id='appendedInputButton' size='16' type='text'/><button class='btn' type='button'>Go!</button></form></div>"); 
        }
    </script>

enter image description here

When a user enters text into the textbox and clicks go, I need it so that the database field server.sb_user is updated to whatever the user entered in that field.

Anyone have suggestions on how to do this?

1 Answer 1

3

What you are searching for is in place editing. Theres a railscast for that:

http://railscasts.com/episodes/302-in-place-editing

Sign up to request clarification or add additional context in comments.

Comments

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.