inline_forms 1.5.6 → 1.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,24 +53,21 @@ class InlineFormsController < ApplicationController
53
53
  @PER_PAGE = 5 unless @parent_class.nil?
54
54
  # if the parent_class is not nill, we are in associated list and we don't search there.
55
55
  # also, make sure the Model that you want to do a search on has a :name attribute. TODO
56
+ conditions = nil
56
57
  if @parent_class.nil? || @Klass.reflect_on_association(@parent_class.underscore.to_sym).nil?
57
- conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ]
58
+ conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ] if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil?
58
59
  else
59
60
  foreign_key = @Klass.reflect_on_association(@parent_class.underscore.to_sym).options[:foreign_key] || @parent_class.foreign_key
60
61
  conditions = [ "#{foreign_key} = ?", @parent_id ]
61
62
  end
62
63
  # if we are using cancan, then make sure to select only accessible records
63
- if cancan_enabled?
64
- @objects = @Klass.accessible_by(current_ability).order(@Klass.table_name + "." + @Klass.order_by_clause).paginate(
64
+ @objects = @Klass
65
+ @objects = @Klass.accessible_by(current_ability) if cancan_enabled?
66
+ @objects = @objects.order(@Klass.table_name + "." + @Klass.order_by_clause) if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil?
67
+ @objects = @objects.paginate(
65
68
  :page => params[:page],
66
69
  :per_page => @PER_PAGE || 12,
67
70
  :conditions => conditions )
68
- else
69
- @objects = @Klass.order(@Klass.table_name + "." + @Klass.order_by_clause).paginate(
70
- :page => params[:page],
71
- :per_page => @PER_PAGE || 12,
72
- :conditions => conditions )
73
- end
74
71
  respond_to do |format|
75
72
  format.html { render 'inline_forms/_list', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html?
76
73
  format.js { render :list }
@@ -122,8 +119,9 @@ class InlineFormsController < ApplicationController
122
119
  @parent_id = params[:parent_id]
123
120
  @PER_PAGE = 5 unless @parent_class.nil?
124
121
  # for the logic behind the :conditions see the #index method.
122
+ conditions = nil
125
123
  if @parent_class.nil? || @Klass.reflect_on_association(@parent_class.underscore.to_sym).nil?
126
- conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ]
124
+ conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ] if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil?
127
125
  else
128
126
  foreign_key = @Klass.reflect_on_association(@parent_class.underscore.to_sym).options[:foreign_key] || @parent_class.foreign_key
129
127
  conditions = [ "#{foreign_key} = ?", @parent_id ]
@@ -131,11 +129,10 @@ class InlineFormsController < ApplicationController
131
129
  end
132
130
  if object.save
133
131
  flash.now[:success] = t('success', :message => object.class.model_name.human)
134
- if cancan_enabled?
135
- @objects = @Klass.accessible_by(current_ability).order(@Klass.table_name + "." + @Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
136
- else
137
- @objects = @Klass.order(@Klass.table_name + "." + @Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
138
- end
132
+ @objects = @Klass
133
+ @objects = @Klass.accessible_by(current_ability) if cancan_enabled?
134
+ @objects = @objects.order(@Klass.table_name + "." + @Klass.order_by_clause) if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil?
135
+ @objects = @objects.paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
139
136
  respond_to do |format|
140
137
  format.js { render :list}
141
138
  end
@@ -42,13 +42,10 @@ they are @object. We need this magic here to rewrite all the @variables to varia
42
42
 
43
43
  <% conditions = [ "#{foreign_key} = ?", parent_id ] %>
44
44
  <% model = attribute.to_s.singularize.camelcase.constantize %>
45
-
46
- <% if cancan_enabled? %>
47
- <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %>
48
- <% else %>
49
- <% objects = parent_class.find(parent_id).send(attribute).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %>
50
- <% end %>
51
-
45
+ <% objects = parent_class.find(parent_id).send(attribute) %>
46
+ <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability) if cancan_enabled? %>
47
+ <% objects = objects.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause) if attribute.to_s.singularize.camelcase.constantize.respond_to?(:order_by_clause) && ! attribute.to_s.singularize.camelcase.constantize.order_by_clause.nil? %>
48
+ <% objects = objects.paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %>
52
49
  <% end %>
53
50
 
54
51
  <%= raw "<ul id=\"#{update_span}\" class=\"inline_forms_list\">" if ul_needed -%>
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineForms
3
- VERSION = "1.5.6"
3
+ VERSION = "1.5.7"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rvm