From b9ace89e53baf9ead31d98d5af3ddda715e8a1cf Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 17 Oct 2011 00:29:22 -0400 Subject: [PATCH] fixes #143: Janitor trials issues --- app/controllers/janitor_trials_controller.rb | 10 +++++++--- app/models/janitor_trial.rb | 4 ++++ app/views/janitor_trials/_secondary_links.html.erb | 6 ++++++ app/views/janitor_trials/demote.js.erb | 1 + app/views/janitor_trials/index.html.erb | 6 ++++-- app/views/janitor_trials/new.html.erb | 6 ++++-- app/views/janitor_trials/promote.js.erb | 1 + 7 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 app/views/janitor_trials/_secondary_links.html.erb create mode 100644 app/views/janitor_trials/demote.js.erb create mode 100644 app/views/janitor_trials/promote.js.erb diff --git a/app/controllers/janitor_trials_controller.rb b/app/controllers/janitor_trials_controller.rb index 89816de43..73a234cd7 100644 --- a/app/controllers/janitor_trials_controller.rb +++ b/app/controllers/janitor_trials_controller.rb @@ -19,18 +19,22 @@ class JanitorTrialsController < ApplicationController def create @janitor_trial = JanitorTrial.create(params[:janitor_trial]) - respond_with(@janitor_trial) + respond_with(@janitor_trial, :location => janitor_trials_path) end def promote @janitor_trial = JanitorTrial.find(params[:id]) @janitor_trial.promote! - respond_with(@janitor_trial) + respond_with(@janitor_trial) do |format| + format.js + end end def demote @janitor_trial = JanitorTrial.find(params[:id]) @janitor_trial.demote! - respond_with(@janitor_trial) + respond_with(@janitor_trial) do |format| + format.js + end end end diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index f11323599..91d44d22f 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -15,6 +15,10 @@ class JanitorTrial < ActiveRecord::Base self.original_level = user.level end + def user_name + user.try(:name) + end + def user_name=(name) self.user_id = User.name_to_id(name) end diff --git a/app/views/janitor_trials/_secondary_links.html.erb b/app/views/janitor_trials/_secondary_links.html.erb new file mode 100644 index 000000000..3a4492509 --- /dev/null +++ b/app/views/janitor_trials/_secondary_links.html.erb @@ -0,0 +1,6 @@ +<% content_for(:secondary_links) do %> + +
  • <%= link_to "Listing", janitor_trials_path %>
  • +
  • <%= link_to "New", new_janitor_trial_path %>
  • +
    +<% end %> diff --git a/app/views/janitor_trials/demote.js.erb b/app/views/janitor_trials/demote.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/janitor_trials/demote.js.erb @@ -0,0 +1 @@ +location.reload(); diff --git a/app/views/janitor_trials/index.html.erb b/app/views/janitor_trials/index.html.erb index cc5949421..a60f0e9a8 100644 --- a/app/views/janitor_trials/index.html.erb +++ b/app/views/janitor_trials/index.html.erb @@ -2,7 +2,7 @@

    Janitor Trials

    - +
    @@ -14,7 +14,7 @@ <% @janitor_trials.each do |janitor_trial| %> - +
    User
    <%= janitor_trial.user.name %><%= janitor_trial.created_at %><%= time_ago_in_words janitor_trial.created_at %> <%= link_to "Promote", promote_janitor_trial_path(janitor_trial), :remote => true, :method => :put %> | <%= link_to "Demote", demote_janitor_trial_path(janitor_trial), :remote => true, :method => :put %> @@ -25,3 +25,5 @@
    + +<%= render "secondary_links" %> \ No newline at end of file diff --git a/app/views/janitor_trials/new.html.erb b/app/views/janitor_trials/new.html.erb index c23737be5..a915bcffb 100644 --- a/app/views/janitor_trials/new.html.erb +++ b/app/views/janitor_trials/new.html.erb @@ -3,8 +3,10 @@

    New Janitor Trial

    <%= simple_form_for(@janitor_trial) do |f| %> - <%= f.input :user_id %> - <%= f.button :submit %> + <%= f.input :user_name %> + <%= f.button :submit, "Submit" %> <% end %> + +<%= render "secondary_links" %> diff --git a/app/views/janitor_trials/promote.js.erb b/app/views/janitor_trials/promote.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/janitor_trials/promote.js.erb @@ -0,0 +1 @@ +location.reload();