Skip to content

Commit

Permalink
Excuses edition
Browse files Browse the repository at this point in the history
  • Loading branch information
aviscasillas authored and Albert Viscasillas Campanyà committed Jan 20, 2014
1 parent 98fab25 commit 93df61c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0-p247
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#= require jquery
#= require jquery_ujs
#= require turbolinks
#= require_tree .
#= require social-share-button
#= require_tree .
16 changes: 16 additions & 0 deletions app/assets/javascripts/excuses.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
click_msg = (msg) ->
if msg.is(':visible')
msg.hide()
else
msg.show()

show_submit_btn = (form) ->
$(form).find('input[type="submit"]').show()

$ ->
$('.excuse .msg').hide()
$('.excuse input[type="submit"]').hide()
$('.excuse label').on 'click', ->
click_msg($(this).parent().find('.msg'))
$('.excuse .msg input[type="text"]').on 'change', ->
show_submit_btn(this.form)
10 changes: 10 additions & 0 deletions app/assets/stylesheets/excuses.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
font-size: 24pt;
font-weight: bold;
}

.excuse {
border: 1px solid;
.msg {
font-size: 10pt;
input[type=text]{
width: 500px;
}
}
}
13 changes: 12 additions & 1 deletion app/controllers/excuses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ExcusesController < ApplicationController
respond_to :html, :json
respond_to :html, :json, :js

def index
@excuses = Excuse.all
Expand All @@ -8,4 +8,15 @@ def index
def rnd
@msg = Excuse.find_rnd.msg[I18n.locale.to_s]
end

def update
@excuse = get_excuse(params[:id])
@excuse.update_attributes!(msg: params[:msg])
end

private

def get_excuse(id)
Excuse.find(id.to_i)
end
end
10 changes: 9 additions & 1 deletion app/views/excuses/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
- @excuses.each do |excuse|
p = excuse.msg
.excuse
= form_for excuse, remote: true do |f|
label = excuse.msg[I18n.locale.to_s]
= f.submit
.msg
= fields_for :msg do |ff|
- excuse.msg.each do |key, value|
div class = key
= ff.text_field key.to_sym, value: value
1 change: 1 addition & 0 deletions app/views/excuses/update.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$('#edit_excuse_<%= @excuse.id %>').find('input[type="submit"]').hide();
3 changes: 0 additions & 3 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ html
body
#content
== yield
#footer
== social_share_button_tag(:hello)
p &copy; Copyright 2013 - 2014 climberexcuses.com - All Rights Reserved

0 comments on commit 93df61c

Please sign in to comment.