[phase-4]edit, update
This commit is contained in:
parent
c56501baa6
commit
fec83eefb5
@ -1,6 +1,6 @@
|
|||||||
class GlossaryTermsController < ApplicationController
|
class GlossaryTermsController < ApplicationController
|
||||||
|
|
||||||
before_action :find_term_from_id, only: [:show]
|
before_action :find_term_from_id, only: [:show, :edit, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@glossary_terms = GlossaryTerm.all
|
@glossary_terms = GlossaryTerm.all
|
||||||
@ -14,9 +14,22 @@ class GlossaryTermsController < ApplicationController
|
|||||||
term = GlossaryTerm.new(glossary_term_params)
|
term = GlossaryTerm.new(glossary_term_params)
|
||||||
if term.save
|
if term.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to glossary_term_path(term.id)
|
redirect_to term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@term.attributes = glossary_term_params
|
||||||
|
if @term.save
|
||||||
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
redirect_to @term
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::StaleObjectError
|
||||||
|
flash.now[:error] = l(:notice_locking_conflict)
|
||||||
|
end
|
||||||
|
|
||||||
# Find the term whose id is the :id parameter
|
# Find the term whose id is the :id parameter
|
||||||
def find_term_from_id
|
def find_term_from_id
|
||||||
|
7
app/views/glossary_terms/edit.html.erb
Normal file
7
app/views/glossary_terms/edit.html.erb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
|
||||||
|
|
||||||
|
<%= labelled_form_for :glossary_term, @term, url: glossary_term_path do |f| %>
|
||||||
|
<%= render partial: 'glossary_terms/form', locals: {form: f} %>
|
||||||
|
<%= f.submit l(:button_edit) %>
|
||||||
|
<% end %>
|
||||||
|
|
@ -1,5 +1,9 @@
|
|||||||
<h2><%=l :label_glossary_terms %></h2>
|
<h2><%=l :label_glossary_terms %></h2>
|
||||||
|
|
||||||
|
<div class="contextual">
|
||||||
|
<%= link_to l(:label_glossary_term_new), new_glossary_term_path, class: 'icon icon-add' %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
<div class="contextual">
|
||||||
|
<%= link_to l(:button_edit), edit_glossary_term_path, class: 'icon icon-edit' %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
|
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
|
||||||
|
|
||||||
<h3><%= @term.name %></h3>
|
<h3><%= @term.name %></h3>
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
# See: http://guides.rubyonrails.org/routing.html
|
# See: http://guides.rubyonrails.org/routing.html
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :glossary_terms, only: [:index, :show, :new, :create]
|
resources :glossary_terms
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user