This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var = nil | |
| counter = 0 | |
| while(var==nil) do | |
| counter = counter + 1 | |
| puts counter | |
| var = true if counter >= 5 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f = File.open("/path/to/some/image.png") | |
| a = AvatarUploader.new(file) | |
| User.create(... | |
| avatar: a | |
| ...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Title | |
| attr_accessor :string | |
| def initialize(string) | |
| @string = string | |
| end | |
| def fix | |
| articles = %w{a of the and And The AND THE} | |
| a = string.split(' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_for current_user do |f| %> | |
| <%= f.hidden_field :role, value: "standard" %> | |
| <%= f.submit %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $("#day-field").change(function(){ | |
| new_val = $(this).val() | |
| if(new_val < 1 || new_val > 31){ | |
| $(this).val(1) | |
| $("#day-field").append("<p>Invalid Date Entered</p>") | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render js: "window.location = '#{root_path}'; $('#flash-notice').html('LOG YO SELF')" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AuthController < ApplicationController | |
| #POST /users/token | |
| def token | |
| user = User.find_by(email: params[:email]) | |
| if user.valid_password?(params[:password]) | |
| respond_with user.authentication_token | |
| else | |
| #handle bad credentials | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Api::SessionsController < ApiController | |
| def create | |
| if params[:username] | |
| @user = User.find_by_username(params[:username]) | |
| token.user = @user if _provided_valid_password? || _provided_valid_api_key? | |
| end | |
| respond_with token | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WelcomeController < ApplicationController | |
| def index | |
| if @user = current_user | |
| @todos = @user.todos.all | |
| else | |
| #Handle unauthenticated user | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Wiki < ActiveRecord::Base | |
| has_many :collabs, dependent: :destroy | |
| has_many :users, through: :collabs | |
| has_one :owner_collab, | |
| -> {where("owner = ?", true)}, | |
| class_name: "Collab" | |
| has_one :owner, through: :owner_collab, source: :user | |
| scope :grouped_collabs, -> { |