Rails 3.1.3

I have succeeded to 'create' a new entry using jQuery Ajax.

If users create new entries from

<div id="script_new">
<%= form_for script, :remote => true do |f| %>
<%= f.hidden_field :video_id %>
<%= f.text_field :startp, :readonly => true %>
<%= f.text_field :text %>
<%= f.submit "save"%>
<% end %>

, the newly created ones will show up in the list

<% for script in scripts %>
<td><%= script.startp %></td>
<td ><%= script.text %></td>
<td><a href="#" class='edit_text' >edit</a></td>
<td><%= link_to 'Destroy', script, :class=>'small', :confirm =>
'Are you sure?', :method => :delete %></td>
<% end %>

I have wrote a JavaScript (jQuery) to add table elements to it.

Now my question is

How can I 'edit' (or 'update') the listed entries above?

Clicking the 'edit' button shown above will retrieve the corresponding
listed entry (script) from the table into the 'create' form. Well,
users may or
may not change the entry (script) there.
Then, naturally they click the 'save' button.

So I need a controller action that works as both 'save' and 'update'.

My 'create' action is follows.

def create
@script = Script.new(params[:script]) #HERE!!!!!!!
respond_to do |format|
if @script.save
format.json { render json: @script, status: :created, location:
notice: 'Script was successfully created.' }
format.html { render action: "new" }
format.json { render json: @script.errors, status:
:unprocessable_entity }

Script object calls for a new instance there. So I'm guessing that
it'll need to be

@script = Script.find(params[:id])

depending on the condition. But I have no clue from here to achieve
'save' or 'update' action.

Could anyone give me tips?



Posted via http://www.ruby-forum.com/.

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.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
postedFeb 13, '12 at 12:44a
activeFeb 13, '12 at 12:44a

1 user in discussion

Soichi Ishida: 1 post



site design / logo © 2021 Grokbase