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 %>
</div>
, the newly created ones will show up in the list
<table>
<% for script in scripts %>
<tr>
<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>
</tr>
<% end %>
</table>
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:
@script,
notice: ''Script was successfully created.'' }
else
format.html { render action: "new" }
format.json { render json: @script.errors, status:
:unprocessable_entity }
end
end
end
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?
Regards.
soichi
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.