Skip to content

Instantly share code, notes, and snippets.

@Jamanius
Created September 19, 2014 05:00
Show Gist options
  • Save Jamanius/eca3bf0e83100c84d5d3 to your computer and use it in GitHub Desktop.
Save Jamanius/eca3bf0e83100c84d5d3 to your computer and use it in GitHub Desktop.
Ridiculously boring app
----------------------- Use coffeeScript -----------------------
app/assets/javascritps/statuses.js.cofee
# instead of document ready in application js, used coffeeScript $ ->
# indentation very important
$ ->
$('.status').hover (event) ->
#console.log("hover triggered")
$(this).toggleClass("hover");
# $(".welcome-notice").hide().show("slow");
----------------------- Devise not playing nicely - copy and paste fix from stack overflow -----------------------
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [:first_name, :last_name, :profile_name]
end
end
----------------------- Use multiple migrations instead of db:reset or -----------------------
db/migrate/23324098234_add_user_to_statuses.rb
class AddUserToStatuses < ActiveRecord::Migration
def change
add_reference :statuses, :user, index: true
end
end
----------------------- Helper method to convert time of status into words -----------------------
app/views/statuses/index.html.erb
<%= link_to time_ago_in_words(status.created_at) + " ago" , status %> |
----------------------- rails delete method which tells rails to delete not treat as post -----------------------
app/views/statuses/index.html.erb
<% if current_user %>
<%= link_to "logout", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "login", new_user_session_path %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment