Skip to content

Commit

Permalink
using decent exposure on BandangosController
Browse files Browse the repository at this point in the history
  • Loading branch information
macool committed Feb 23, 2014
1 parent 85c7a95 commit 09c07e6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 43 deletions.
29 changes: 10 additions & 19 deletions app/controllers/bandangos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
class BandangosController < BusinessController
before_action :find_bandango, only: [:show, :edit, :update]
before_action :find_connections, only: [:show, :create, :update]

def show
end

def edit
end
expose(:bandango) {
business.bandangos.find params[:id]
}
expose(:connections) {
bandango.connections.page(params[:page]).per(10)
}

def new
@bandango = @business.bandangos.new
self.bandango = business.bandangos.new
end

def create
@bandango = @business.bandangos.new bandango_params
if @bandango.save
self.bandango = business.bandangos.new bandango_params
if bandango.save
flash.now[:notice] = "Creado"
render :show
else
Expand All @@ -24,7 +23,7 @@ def create
end

def update
if @bandango.update_attributes(bandango_params)
if bandango.update_attributes(bandango_params)
flash.now[:notice] = "Actualizado"
render :show
else
Expand All @@ -35,15 +34,7 @@ def update

private

def find_bandango
@bandango = Bandango.cached_find params[:id]
end

def bandango_params
params.require(:bandango).permit(:name)
end

def find_connections
@connections = @bandango.connections.page(params[:page]).per(10)
end
end
12 changes: 6 additions & 6 deletions app/controllers/business_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class BusinessController < ApplicationController
before_action :require_login, :set_active, :find_business
class BusinessController < BusinessesController
before_action :require_login, :set_active

expose(:business) {
businesses.find params[:business_id]
}

protected

def set_active
@navbar_active = "businesses"
end
def find_business
@business = Business.cached_find params[:business_id]
end

end
6 changes: 3 additions & 3 deletions app/views/bandango_connections/_bandango_connections.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% if @connections.any? %>
<% @connections.each do |connection| %>
<% if connections.any? %>
<% connections.each do |connection| %>
<%= render connection %>
<% end %>
<div class="align_center">
<%= paginate @connections, remote: true %>
<%= paginate connections, remote: true %>
</div>
<% else %>
Ninguna
Expand Down
16 changes: 8 additions & 8 deletions app/views/bandangos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<h3>
<%= @bandango.new_record? ? "Nuevo" : "Editar" %>
<%= bandango.new_record? ? "Nuevo" : "Editar" %>
</h3>

<%= form_for [@business, @bandango] do |f| %>
<%= form_errors_for @bandango %>
<%= form_for [business, bandango] do |f| %>
<%= form_errors_for bandango %>

<div class="form-group">
<%= f.label :name, "Nombre" %>
<%= f.text_field :name, :class => "form-control", required: true %>
</div>
</div>
<div class="actions">
<% if @bandango.new_record? %>
<%= link_to "Cancelar", business_path(@business), :class => "btn btn-link" %>
<% if bandango.new_record? %>
<%= link_to "Cancelar", business_path(business), :class => "btn btn-link" %>
<% else %>
<%= link_to "Cancelar", business_bandango_path(@business, @bandango), :class => "btn btn-link" %>
<%= link_to "Cancelar", business_bandango_path(business, bandango), :class => "btn btn-link" %>
<% end %>
<%= f.submit "Enviar", :class => "btn btn-default", data: { disable_with: "Enviando.." } %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/bandangos/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= link_to business.nombre, business_path(business) %>
</li>
<li>
<%= link_to @bandango.nombre, business_bandango_path(business, @bandango) %>
<%= link_to bandango.nombre, business_bandango_path(business, bandango) %>
</li>
<li class="active">Editar</li>
</ol>
Expand Down
2 changes: 1 addition & 1 deletion app/views/bandangos/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to "Negocios", businesses_path %>
</li>
<li>
<%= link_to @business.nombre, business_path(@business) %>
<%= link_to business.nombre, business_path(business) %>
</li>
<li class="active">Nuevo</li>
</ol>
Expand Down
10 changes: 5 additions & 5 deletions app/views/bandangos/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<%= link_to "Negocios", businesses_path %>
</li>
<li>
<%= link_to @business.nombre, business_path(@business) %>
<%= link_to business.nombre, business_path(business) %>
</li>
<li class="active"><%= @bandango.nombre %></li>
<li class="active"><%= bandango.nombre %></li>
</ol>

<h3><%= @bandango.nombre %></h3>
<h3><%= bandango.nombre %></h3>

<div>
token:
<code class="token"><%= @bandango.token %></code>
<code class="token"><%= bandango.token %></code>
</div>

<%= link_to "Editar", edit_business_bandango_path(@business, @bandango), :class => "btn btn-link" %>
<%= link_to "Editar", edit_business_bandango_path(business, bandango), :class => "btn btn-link" %>

<h4>Conexiones</h4>
<div class="well bandango_connections models">
Expand Down

0 comments on commit 09c07e6

Please sign in to comment.