Skip to content

Instantly share code, notes, and snippets.

@thebusiness11
thebusiness11 / form.html.erb
Created December 17, 2012 09:04
Issues with parameters trying to use params[:hashtag]
<%= form_for(@hash_create, :url => hashtags_path, :validate => :hashtag_validators, remote: true) do |f| %>
<div class="input-prepend input-append">
<span class="add-on swag">#</span>
<%= f.text_field :hashtag ,class: "span4 swag_text_field", id:"appendedPrependedInput", data: {autocomplete_source: autocomplete_index_path} %>
<%= f.submit "VS!", class: "btn add-on-right swag_button" %>
<% end %>
@thebusiness11
thebusiness11 / Hashtag _contoller.rb
Created December 16, 2012 02:38
I am trying to catch the validation errors and return them via jQuery. I but it seems to have a no method error when the tweet is valid. And does not run the else format.js and trigger the failure.js.erb
def create
@hash_create = Hashtag.create_hashtag(params[:hashtag])
Hashlog.create_hashlog(params[:hashtag])
@random_hashtag_pull = Hashtag.random_hashtags_pull
@leaderboard = Hashtag.leaderboard_history_current
respond_to do |format|
if @hash_create
format.html { redirect_to root_path }
format.js
else
@thebusiness11
thebusiness11 / current_hashtag.rb
Created December 15, 2012 15:38
refactoring code
def create_hashtag(hashtag) #creates new tweetvstweet for inputed hashtag with # for guests
dash = "#"
@hashtag_scrubbed = [dash, hashtag].join.downcase
if User.current_user
User.current_user.twitter.search("%#{@hashtag_scrubbed}", :lang => "en", :count => 100, :result_type => "mixed").results.map do |tweet|
unless exists?(tweet_id: tweet.id)
create!(
tweet_id: tweet.id,
text: tweet.text,
profile_image_url: tweet.user.profile_image_url,
@thebusiness11
thebusiness11 / Error
Created December 14, 2012 00:17
I am trying to run a method where if a (table Hashtag column tag) tag exists it updates the view count by 1. else it will create a new row with a default view count of 0 and a tag of @hashtag scrubbed.
Completed 500 Internal Server Error in 772ms
NoMethodError (undefined method `+' for nil:NilClass):
app/models/hashlog.rb:24:in `create_hashlog'
app/controllers/hashtags_controller.rb:32:in `create'
@thebusiness11
thebusiness11 / _vote.html.erb
Created December 8, 2012 03:46
post to vote
<%= form_tag(hashtags_path, :method => :vote) do %>
<div id="hashtags" class="twitter-hashtag-voting-block-v1">
<% @random_hashtag_pull.each do |hashtag| %>
<div class="span4 twitter-spans-v1" id="<%= hashtag.id %>">
<div id="tweet-block-v1" class="hashtag-tweet-database-container">
<div class="tweet-block-border-v1">
<div class="tweet-block-spacing-v1">
<div class="twitter-block-author-v1">
<a class="twitter-block-user-v1" target="_blank" href="https://twitter.com/<%= hashtag.from_user %>">
<span class="twitter-author-image-v1"><img alt="" class="twitter-author-image-photo-v1" src="<%= hashtag.profile_image_url %>"></span>
@thebusiness11
thebusiness11 / error
Created December 7, 2012 05:49
Update View Count
Completed 500 Internal Server Error in 299ms
ActionView::Template::Error (undefined method `+' for nil:NilClass):
1: <div id="hashtags" class="twitter-hashtag-voting-block-v1">
2: <% @random_hashtag_pull.each do |hashtag| %>
3: <div class="span4 twitter-spans-v1" id="<%= hashtag.id %>">
4: <div id="tweet-block-v1" class="hashtag-tweet-database-container">
5: <div class="tweet-block-border-v1">
app/models/hashtag.rb:46:in `update_view_count'
app/views/shared/_vote_tweets.html.erb:2:in `_app_views_shared__vote_tweets_html_erb__2738953379660121418_70243350609340'
@thebusiness11
thebusiness11 / error
Created December 3, 2012 06:43
squeel
Started POST "/hashtags" for 127.0.0.1 at 2012-12-02 22:41:48 -0800
Processing by HashtagsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"knGCscj0fV+LfVsi0mXKrmRtK+g8mog6kRrOH6XSEmo=", "hashtag"=>"#tweetvstweet", "commit"=>"Swag!"}
Hashtag Exists (0.3ms) SELECT 1 AS one FROM "hashtags" WHERE "hashtags"."tweet_id" = 274371071875108864 LIMIT 1
Hashtag Exists (0.3ms) SELECT 1 AS one FROM "hashtags" WHERE "hashtags"."tweet_id" = 273165002188390400 LIMIT 1
Hashtag Load (0.3ms) SELECT "hashtags".* FROM "hashtags" WHERE "hashtags"."hashtag" ILIKE []("params"."hashtag") LIMIT 12
PG::Error: ERROR: syntax error at or near "["
LINE 1: ...FROM "hashtags" WHERE "hashtags"."hashtag" ILIKE []("params...
^
: SELECT "hashtags".* FROM "hashtags" WHERE "hashtags"."hashtag" ILIKE []("params"."hashtag") LIMIT 12
<% @random_hashtags.each do |hashtag| %>
<div class="span4 twitter-spans-v1">
<div id="tweet-block-v1" class="hashtag-tweet-database-container">
<div class="tweet-block-border-v1">
<div class="tweet-block-spacing-v1">
<div class="twitter-block-author-v1">
<a class="twitter-block-user-v1" target="_blank" href="https://twitter.com/<%= hashtag.from_user %>">
<span class="twitter-author-image-v1"><img alt="" class="twitter-author-image-photo-v1" src="<%= hashtag.profile_image_url %>"></span>
<span class="twitter-author-name-v1"><%= hashtag.from_user_name %></span>
<span class="twitter-author-nickname-v1">@<%= hashtag.from_user %></span>
@thebusiness11
thebusiness11 / Second Run
Created December 2, 2012 03:58
Stuck in memory
Second Run - Passing through the :hashtag param of #espn - but its still entering #google and running the Model with #google
Started POST "/hashtags" for 127.0.0.1 at 2012-12-01 19:56:11 -0800
Processing by HashtagsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"S+zHymXZNf8MeCxbtHqPIr+n4KEXj7XUQzZQoUWCTus=", "hashtag"=>"#espn", "commit"=>"Swag!"}
Hashtag Exists (0.2ms) SELECT 1 AS one FROM "hashtags" WHERE "hashtags"."tweet_id" = 275085566339608576 LIMIT 1
(0.2ms) BEGIN
SQL (0.4ms) INSERT INTO "hashtags" ("created_at", "from_user", "hashtag", "profile_image_url", "text", "tweet_id", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["created_at", 2012-12-01 19:54:44 -0800], ["from_user", "PascalC"], ["hashtag", "#google"], ["profile_image_url", "http://si0.twimg.com/profile_images/584147642/voilier_normal.jpg"], ["text", "RT @allthingsd: Google’s SEM Platform is Mediocre, Which is Fine… for Google http://t.co/3AMMvS2w #kenshoo #Google"], ["tweet_id", 27
ActiveModel::MassAssignmentSecurity::Error in HashtagsController#create
Can't mass-assign protected attributes: content, profile_image, screen_name, tweet_date