0

What i have: A table generated by single cells of values like:

<tr>
  <%= render :partial => 'partials/fieldtypes/show_in_table', :locals => {:fieldtype => 'textline', :data => {'object' => object, 'value' => 'name'}, :vars => {'textline' => object.name}} %>
  <%= render :partial...
</tr>

The partial looks like this:

<td class='tablecell' <% data.each do |dat| %>data-<%= raw(dat[0]) %>='<%= raw(dat[1]) %>' <% end %> >
  <%= render :partial => 'partials/fieldtypes/show/'+fieldtype, :locals => {:vars => vars} %>
</td>

Now i want to edit single entries/cells of that table like in MS Excel by doubleclicking on them. The site is running on full javascript, so pages are not being linked.

So what i want is: Generating (not prerendering and switching visibility!) a form everytime the user wants to edit a field (by doubleclicking).

My ideas so far: As you can see i was trying to store all the necessary data in html5 data-tags to generate the form. The plan was to call a controller action everytime a cell is doubleclicked and to generate the form with the database connection with rails.

Problem/Question: Does this work that way? Because the data in the tags looks converted and useless for further interaction. And if it works: How do i create a controller action for that with a proper route?

Or are there any easier solutions? As stated i do not want to render the form hidden directly!

3
  • 1
    Calling a controller action every time a cell is double-clicked sounds like it could using make your site painful for people with any significant lag on their Internet connection. I would suggest implementing the desired functionality purely in Javascript (perhaps using JQuery, etc). Catching a double-click event on a DOM element and then dynamically creating a text field sounds like it should be fairly easy to do. Commented Jul 4, 2012 at 21:30
  • @AlexD how can i generate a form dynamically with jQuery? If i have a dynamic select field i need to connect to the database before generating the form, else the available options will only update on refreshing the page. Any idea how to do that? Commented Jul 4, 2012 at 22:24
  • I would preload the data into a JS array/hash when the page is first loaded, then dynamically generate forms using that. I don't know jQuery well, but in JS you can easily build a HTML string and add it as a new DOM node under a given <div>. I'm sure jQuery has a method to do the same thing. Commented Jul 5, 2012 at 8:54

1 Answer 1

1

Check this gem out it is exactly what you want to do https://github.com/bernat/best_in_place

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.