Skip to content

Commit

Permalink
Wow, that was easy. Lookups for dynamic selects are now in their resp…
Browse files Browse the repository at this point in the history
…ective controllers.
  • Loading branch information
tumes committed Apr 26, 2011
1 parent 59ce8bd commit 11be190
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
14 changes: 14 additions & 0 deletions app/controllers/chromatographic_columns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ def update
update!(:notice => 'Column successfull edited') { chromatographic_columns_path }
end

def show
show! do |format|
format.html
format.js { associated_columns_lookup }
end
end

private

def associated_columns_lookup
@dynamic_columns = ChromatographicColumn.find(:all, :conditions => ["analytical_method_id = ?", params[:id]])
render :json => @dynamic_columns
end

end
16 changes: 16 additions & 0 deletions app/controllers/instruments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class InstrumentsController < InheritedResources::Base
before_filter :authenticate_user!
respond_to :html
respond_to :js, :only => :index

def create
create!(:notice => 'New instrument created.') { instruments_path }
Expand All @@ -8,4 +10,18 @@ def create
def update
update!(:notice => 'Instrument successfully edited.') { instruments_path }
end

def show
show! do |format|
format.html
format.js { associated_methods_lookup }
end
end

private

def associated_methods_lookup
@dynamic_methods = AnalyticalMethod.find(:all, :conditions => ["instrument_id = ?", params[:id]])
render :json => @dynamic_methods
end
end
14 changes: 0 additions & 14 deletions app/controllers/run_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,4 @@ def create
create!(:notice => 'New run logged.'){ run_logs_path }
end

def for_analytical_method_id
@dynamic_methods = AnalyticalMethod.find(:all, :conditions => ["instrument_id = ?", params[:id]])
respond_to do |format|
format.json { render :json => @dynamic_methods }
end
end

def for_chromatographic_column_id
@dynamic_columns = ChromatographicColumn.find(:all, :conditions => ["analytical_method_id = ?", params[:id]])
respond_to do |format|
format.json { render :json => @dynamic_columns }
end
end

end
5 changes: 2 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
get 'intro'
end
end

match 'run_logs/for_analytical_method_id/:id', :controller => 'run_logs', :action => 'for_analytical_method_id'
match 'run_logs/for_chromatographic_column_id/:id', :controller => 'run_logs', :action => 'for_chromatographic_column_id'

match 'analytical_methods/:id', :controller => 'instruments', :action => 'show'

resources :analytical_standards do
collection do
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $(document).ready(function() {
$.ajax({
dataType: "json",
cache: false,
url: '/run_logs/for_' + next_select_id + '_id/' + id_value_string,
url: '/' + next_select_id + 's/' + id_value_string,
timeout: 2000,
error: function(XMLHttpRequest, errorTextStatus, error){
alert("Failed to submit : "+ errorTextStatus+" ;"+error);
Expand Down

0 comments on commit 11be190

Please sign in to comment.