Skip to content

Commit 96fa377

Browse files
committed
minor organizations code clean up
1 parent c775567 commit 96fa377

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

app/controllers/organizations_controller.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
class OrganizationsController < ApplicationController
2-
before_filter :load_resource
3-
4-
def load_resource
5-
if params[:id]
6-
@organization = Organization.find(params[:id])
7-
else
8-
@organizations = Organization.all
9-
end
10-
end
2+
before_filter :load_resource, except: [:new, :index, :create]
113

124
def new
135
@organization = Organization.new
146
end
157

168
def index
17-
@organizations = @organizations.matching(params[:q]) if params[:q].present?
9+
@organizations = Organization.all
1810
end
1911

2012
def show
@@ -27,7 +19,8 @@ def show
2719
end
2820

2921
def create
30-
@organization = @organizations.build organization_params
22+
@organization = Organization.new(organization_params)
23+
3124
if @organization.save
3225
redirect_to @organization, status: :created
3326
else
@@ -57,6 +50,10 @@ def set_current
5750

5851
private
5952

53+
def load_resource
54+
@organization = Organization.find(params[:id])
55+
end
56+
6057
def organization_params
6158
params[:organization].permit(*%w[name theme email phone web
6259
public_opening_times description address

app/models/organization.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ class Organization < ActiveRecord::Base
22
has_many :members, dependent: :destroy
33
has_many :users, -> { order "members.created_at DESC" }, through: :members
44
has_many :all_accounts, class_name: "Account", inverse_of: :organization
5-
has_many :all_movements, class_name: "Movement", through: :all_accounts, source: :movements do
6-
def with_transfer
7-
joins(transfer: :movements)
8-
end
9-
end
5+
has_many :all_movements, class_name: "Movement", through: :all_accounts, source: :movements
106
has_many :all_transfers, class_name: "Transfer", through: :all_movements, source: :transfer
117
has_one :account, as: :accountable
128
has_many :member_accounts, through: :members, source: :account
@@ -15,11 +11,7 @@ def with_transfer
1511
has_many :inquiries
1612
has_many :documents, as: :documentable
1713

18-
scope :matching, ->(str) {
19-
where(Organization.arel_table[:name].matches("%#{str}%"))
20-
}
21-
22-
validates :name, uniqueness: true
14+
validates :name, presence: true, uniqueness: true
2315

2416
before_validation :ensure_url
2517
after_create :create_account

app/views/organizations/_form.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<%= show_error_messages!(@organization) %>
12
<%= simple_form_for @organization do |f| %>
23
<%= f.input :name %>
34
<%= f.input :email %>

app/views/organizations/edit.html.erb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<% if @organization.errors.present? %>
2-
<% @organization.errors.full_messages.each do |msg| %>
3-
<div class="alert alert-danger" role="alert">
4-
<%= msg %>
5-
</div>
6-
<% end %>
7-
<% end %>
81
<h1>
92
<%= link_to @organization, organization_path(@organization) %>
103
<small><%= t 'global.edit' %></small>

app/views/organizations/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<%= Organization.model_name.human(count: :many) %>
33
</h1>
44

5-
<ul class="nav nav-pills">
5+
<ul class="nav navbar-nav pull-right">
66
<% if superadmin? %>
77
<li>
88
<%= link_to new_organization_path do %>

0 commit comments

Comments
 (0)