FRAMEWORK » RUBY_ON_RAILS » TUTORIAL
Edit form save
Save the data to the controller
ruby
## app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
# ...
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
# ...
end
Add link to the edit page
erb
<!-- app/views/articles/index.html.erb -->
<%= link_to 'New article', new_article_path %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="2"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
</tr>
<% end %>
</table>
erb
<!-- app/views/articles/show.html.erb -->
<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>