Commit 6121466ffb6847a618f6bb82c5f5067c59b9db51

Authored by vinicim
Committed by Rafael Manzo
1 parent 382ad046

some changes in edit and new forms to solve editing problems

app/controllers/repositories_controller.rb
1 1 class RepositoriesController < ApplicationController
2 2 before_action :set_repository, only: [:show, :edit, :update, :destroy]
3 3  
  4 +
  5 + $project_id = 0
  6 +
4 7 # GET /repositories
5 8 # GET /repositories.json
6 9 def index
... ... @@ -24,6 +27,7 @@ class RepositoriesController &lt; ApplicationController
24 27  
25 28 # GET /repositories/1/edit
26 29 def edit
  30 + $project_id = params[:project_id]
27 31 @project = Project.find(params[:project_id])
28 32 set_repository
29 33 @repository_types = KalibroEntities::Entities::Repository.repository_types
... ... @@ -53,9 +57,10 @@ class RepositoriesController &lt; ApplicationController
53 57 # PATCH/PUT /repositories/1
54 58 # PATCH/PUT /repositories/1.json
55 59 def update
  60 + @project = $project_id
56 61 respond_to do |format|
57 62 if @repository.update(repository_params)
58   - format.html { redirect_to @repository, notice: 'Repository was successfully updated.' }
  63 + format.html { redirect_to(project_repository_path(@project, @repository.id), notice: 'Repository was successfully updated.') }
59 64 format.json { head :no_content }
60 65 else
61 66 format.html { render action: 'edit' }
... ...
app/views/repositories/_form.html.erb
1   -<%= form_for(@repository, :url => project_repositories_url(@project.id)) do |f| %>
  1 +<%= render :partial => 'shared/form_errors', :locals => {:object => @repository} %>
2 2  
3   - <%= render :partial => 'shared/form_errors', :locals => {:object => @repository} %>
  3 +<% if @repository.errors.any? %>
  4 + <div id="error_explanation">
  5 + <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2>
4 6  
5   - <% if @repository.errors.any? %>
6   - <div id="error_explanation">
7   - <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2>
  7 + <ul>
  8 + <% @repository.errors.full_messages.each do |msg| %>
  9 + <li><%= msg %></li>
  10 + <% end %>
  11 + </ul>
  12 + </div>
  13 +<% end %>
8 14  
9   - <ul>
10   - <% @repository.errors.full_messages.each do |msg| %>
11   - <li><%= msg %></li>
12   - <% end %>
13   - </ul>
14   - </div>
15   - <% end %>
  15 +<div class="field">
  16 + <%= f.label :name %><br>
  17 + <%= f.text_field :name %>
  18 +</div>
16 19  
17   - <div class="field">
18   - <%= f.label :name %><br>
19   - <%= f.text_field :name %>
20   - </div>
  20 +<div class="field">
  21 + <%= f.label :type %><br>
  22 + <%= f.select( :type, @repository_types ) %>
  23 +</div>
21 24  
22   - <div class="field">
23   - <%= f.label :type %><br>
24   - <%= f.select( :type, @repository_types ) %>
25   - </div>
  25 +<div class="field">
  26 + <%= f.label :addres %><br>
  27 + <%= f.text_field :address %>
  28 +</div>
26 29  
27   - <div class="field">
28   - <%= f.label :addres %><br>
29   - <%= f.text_field :address %>
30   - </div>
  30 +<div class="field">
  31 + <%= f.label :configuration %><br/>
  32 + <% configuration_list = KalibroEntities::Entities::Configuration.all.map { |conf| [conf.name, conf.id] } %>
  33 + <%= f.select( :configuration_id, configuration_list ) %>
  34 +</div>
31 35  
32   - <div class="field">
33   - <%= f.label :configuration %><br/>
34   - <% configuration_list = KalibroEntities::Entities::Configuration.all.map { |conf| [conf.name, conf.id] } %>
35   - <%= f.select( :configuration_id, configuration_list ) %>
36   - </div>
  36 +<div class="actions">
  37 + <%= f.submit %>
  38 +</div>
37 39  
38   - <div class="actions">
39   - <%= f.submit %>
40   - </div>
41   -<% end %>
... ...
app/views/repositories/edit.html.erb
1 1 <h1>Editing repository</h1>
2   -
3   -<%= render 'form' %>
  2 +<%= form_for(@repository, :url => project_repository_update_url(@project, @repository.id), method: :put) do |f| %>
  3 + <%= render partial: 'form', locals: {f: f} %>
  4 +<% end %>
4 5  
5 6 <%= link_to 'Show', project_repository_path(@project, @repository) %> |
6 7 <%= link_to 'Back', project_repositories_path(@project) %>
... ...
app/views/repositories/new.html.erb
1 1 <h1>New Repository</h1>
2 2  
3   -<%= render 'form' %>
  3 +<%= form_for(@repository, :url => project_repositories_url(@project.id)) do |f| %>
  4 + <%= render partial: 'form', locals: {f: f} %>
  5 +<% end %>
4 6  
5 7 <%= link_to 'Back', project_path(@project)%>
  8 +
  9 +
... ...
config/routes.rb
... ... @@ -7,7 +7,8 @@ Mezuro::Application.routes.draw do
7 7 #resources :projects
8 8  
9 9 resources :projects do
10   - resources :repositories
  10 + resources :repositories, except: :update
  11 + put '/repositories/:id' => 'repositories#update', as: :repository_update
11 12 end
12 13 # The priority is based upon order of creation: first created -> highest priority.
13 14 # See how all your routes lay out with "rake routes".
... ...