Commit 3287c5d16dce63a791f13ccfbfa353f8a6b18909

Authored by Vinicius Vieira
Committed by Rafael Manzo
1 parent 2f4de8aa

the problem founded on new repository button was removed

app/controllers/repositories_controller.rb
... ... @@ -29,18 +29,22 @@ class RepositoriesController < ApplicationController
29 29 # POST /repositories.json
30 30 def create
31 31 @project = Project.find(params[:project_id])
32   - @repository = @project.repositories.create(params[:repository].permit(:name, :type, :address, :configuration_id))
33   - redirect_to @project
  32 + #@repository = @project.repositories.create(params[:repository].permit(:name, :type, :address, :configuration_id))
34 33  
35   - #respond_to do |format|
36   - # if @repository.save
37   - # format.html { redirect_to @repository, notice: 'Repository was successfully created.' }
38   - # format.json { render action: 'show', status: :created, location: @repository }
39   - #else
40   - # format.html { render action: 'new' }
41   - #format.json { render json: @repository.errors, status: :unprocessable_entity }
42   - #end
43   - #end
  34 + @repository = Repository.new
  35 +
  36 + @repository.project_id = @project.id
  37 +
  38 +
  39 + respond_to do |format|
  40 + if @repository.save
  41 + format.html { redirect_to @repository, notice: 'Repository was successfully created.' }
  42 + format.json { render action: 'show', status: :created, location: @repository }
  43 + else
  44 + format.html { render action: 'new' }
  45 + format.json { render json: @repository.errors, status: :unprocessable_entity }
  46 + end
  47 + end
44 48 end
45 49  
46 50 # PATCH/PUT /repositories/1
... ...
app/controllers/repositories_controller.rb~
... ... @@ -5,7 +5,6 @@ class RepositoriesController < ApplicationController
5 5 # GET /repositories.json
6 6 def index
7 7 @project = Project.find(params[:project_id])
8   - set_repository
9 8 @repositories = Repository.repositories_of(params[:project_id])
10 9 end
11 10  
... ... @@ -23,13 +22,19 @@ class RepositoriesController < ApplicationController
23 22  
24 23 # GET /repositories/1/edit
25 24 def edit
  25 + @project = Project.find(params[:project_id])
26 26 end
27 27  
28 28 # POST /repositories
29 29 # POST /repositories.json
30 30 def create
31 31 @project = Project.find(params[:project_id])
32   - @repository = @project.repositories.create(params[:repository].permit(:name, :type, :address, :configuration_id))
  32 + #@repository = @project.repositories.create(params[:repository].permit(:name, :type, :address, :configuration_id))
  33 +
  34 + @repository = Repository.new
  35 +
  36 + @repository.project_id = @project.id
  37 +
33 38 redirect_to @project
34 39  
35 40 #respond_to do |format|
... ...
app/models/project.rb
... ... @@ -6,6 +6,10 @@ class Project < KalibroEntities::Entities::Project
6 6 attr_accessor :name
7 7 validates :name, presence: true, kalibro_uniqueness: true
8 8  
  9 + def repositories
  10 + KalibroEntities::Entities::Repository.repositories_of(self.id)
  11 + end
  12 +
9 13 def self.latest(count = 1)
10 14 all.sort { |a,b| b.id <=> a.id }.first(count)
11 15 end
... ...
app/models/project.rb~ 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require "validators/kalibro_uniqueness_validator.rb"
  2 +
  3 +class Project < KalibroEntities::Entities::Project
  4 + include KalibroRecord
  5 +
  6 + attr_accessor :name
  7 + validates :name, presence: true, kalibro_uniqueness: true
  8 +
  9 +
  10 + def self.latest(count = 1)
  11 + all.sort { |a,b| b.id <=> a.id }.first(count)
  12 + end
  13 +end
... ...
app/views/repositories/_form.html.erb
1   -<%= form_for(@repository) do |f| %>
  1 +<%= form_for(@repository, :url => project_repositories_url(@project.id)) do |f| %>
  2 +
  3 + <%= render :partial => 'shared/form_errors', :locals => {:object => @repository} %>
  4 +
2 5 <% if @repository.errors.any? %>
3 6 <div id="error_explanation">
4 7 <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2>
... ...
app/views/repositories/_form.html.erb~
1   -<%= form_for(@repository) do |f| %>
  1 +<%= form_for(@repository, :url => project_repositories_url(@project.id)) do |f| %>
  2 +
2 3 <% if @repository.errors.any? %>
3 4 <div id="error_explanation">
4 5 <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2>
... ... @@ -28,7 +29,7 @@
28 29  
29 30 <div class="field">
30 31 <%= f.label :configuration %><br>
31   - <%= f.text_field :configuration %>
  32 + <%= f.text_field :configuration_id %>
32 33 </div>
33 34 <div class="actions">
34 35 <%= f.submit %>
... ...