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
Hey guys, since current_user is a method used in every request I decided to give it a few benchmarks | |
I'm gisting this so if anyone may find good literature | |
here was my start point question: | |
which is best? | |
(yes this approach doesn't validate an auth token) | |
def current_user | |
if session[:user_id] |
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 Post | |
def youtube_url=(value) | |
self.youtube=value.gsub("http://.../","") | |
end | |
def youtube_url | |
youtube | |
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
belongs_to :gift | |
belongs_to :user |
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
<style> | |
body { | |
margin: 0px; | |
padding: 0px; | |
} | |
#myCanvas { | |
border: 1px solid red; | |
width: 99.9%; | |
height: 1000px; |
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
[user@red ~]$ gem install pg | |
Building native extensions. This could take a while... | |
ERROR: Error installing pg: | |
ERROR: Failed to build gem native extension. | |
/home/user/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb | |
checking for pg_config... yes | |
Using config values from /usr/bin/pg_config | |
checking for libpq-fe.h... no | |
Can't find the 'libpq-fe.h header |
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
def link_to_profile_dropdown(user) | |
link_to "#", :class => "dropdown-toggle", "data-toggle" => "dropdown" do | |
"#{user.email} <b class='caret'></b>" | |
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
<% module_namespacing do -%> | |
class <%= controller_class_name %>Controller < ApplicationController | |
# TODO: name these comments properly with all the matching URLs to each action | |
# GET <%= route_url %> | |
def index | |
@<%= plural_table_name %> = <%= orm_class.all(class_name) %> | |
end | |
# GET <%= route_url %>/1 |
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
<jarr0dsz> im having a @group.participants.order(:id).offset(0).limit(1).first that returns a participant object i checked with .inspect but how do i get an attribute from that? | |
first_participant = @group.participants.order("id").select("name").first || :no_participant_for_this_group | |
if first_participant == :no_participant_for_this_group | |
puts first_participant.name | |
else |
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
def consent | |
@user = current_user | |
if @user.update_attributes(params[:user])#this is really dangerous, I could force my email to change form the form =/ | |
redirect_to :back, notice: "Error updating your user account" | |
else | |
flash[:notice] = 'User information updated' | |
@cart.consent_updated = false | |
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
if | |
@sentiment["mood"] == positive && @sentiment["prob"] > 0.94 | |
@tag.score = 100 | |
elsif | |
@sentiment["mood"] == positive && @sentiment["prob"] > 0.89 | |
@tag.score = 96 | |
elsif | |
@sentiment["mood"] == positive && @sentiment["prob"] > 0.84 | |
@tag.score = 92 | |
elsif |