Coder Social home page Coder Social logo

bodrovis / sitepoint-source Goto Github PK

View Code? Open in Web Editor NEW
217.0 27.0 440.0 1.01 MB

Source code for my articles on Sitepoint (since March 2015)

Home Page: http://www.sitepoint.com/author/ibodrov/

Ruby 69.72% JavaScript 7.71% CoffeeScript 0.58% CSS 1.28% HTML 18.78% TypeScript 1.94%
ruby article sitepoint rails education examples

sitepoint-source's Introduction

Source code for articles on SitePoint

This repo contains source code for my articles on SitePoint (starting from March 2015).

Source code for previous articles can be found in the corresponding repos.

Follow me on Twitter to be the first to know about my new articles!

Reporting issues / asking questions

I am really glad when I receive feedback and questions from you guys because this means my articles are interesting and useful. After all I am doing this for you as I really love teaching :).

Quite often I receive questions on how to extend some solution further or fix some kind of an error. I'm trying to be as helpful as possible but please help me a bit as well. So, when sending me a question via e-mail or when reporting an issue here on GitHub:

  • Specify which article are we talking about.
  • If you need help with an error, provide that error! This seems obvious but sometimes people just forget to do so.
  • Error stack trace is always very much welcome.
  • If possible, list some pieces of relevant code or provide a link to the GitHub repo if your project is open source. If, for some reason, you can't reveal your code (due to privacy policies, for example) - that's okay, we'll deal with this somehow.
  • Try to overcome the problem yourself before contacting me and list the solutions you've already tried. Still, if you have absolutely no clue of what to do - go ahead and write me right away.
  • If you are reporting an issue on GitHub, write in English because other people might experience the same problem. I am able to understand some other languages (Russian, Ukrainian, Polish), well, at some basic level at least, but still English is preferred.
  • If you want me to cover a specific topic, try to provide some exact details on what has to be covered. Articles can't be too long and therefore topics like "how to write automated tests" or "how to write cool Rails apps" aren't suitable. There are many good books about Ruby and Rails in general out there :).

The more information you provide the faster we will be able to find a solution. Thank you for your understanding and please don't hesitate to contact me :).

Legals

(c) Ilya Bodrov (bodrovis.tech)

sitepoint-source's People

Contributors

bodrovis avatar kutanov avatar tbarbugli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sitepoint-source's Issues

Everything is working but when I try to send a message, after submitting the form it gives me this error message: No route matches [POST] "/chat_rooms/1"

The tutorial I followed is:
https://github.com/bodrovis/Sitepoint-source/tree/master/Chat_with_ActionCable_and_Devise

The full trace of the error is:

actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in call' web-console (3.6.2) lib/web_console/middleware.rb:135:in call_app'
web-console (3.6.2) lib/web_console/middleware.rb:30:in block in call' web-console (3.6.2) lib/web_console/middleware.rb:20:in catch'
web-console (3.6.2) lib/web_console/middleware.rb:20:in call' actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in call_app' railties (5.2.0) lib/rails/rack/logger.rb:26:in block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in block in tagged' activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in tagged' railties (5.2.0) lib/rails/rack/logger.rb:26:in call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in call' rack (2.0.5) lib/rack/method_override.rb:22:in call'
rack (2.0.5) lib/rack/runtime.rb:22:in call' activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in call' actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in call'
rack (2.0.5) lib/rack/sendfile.rb:111:in call' railties (5.2.0) lib/rails/engine.rb:524:in call'
puma (3.11.4) lib/puma/configuration.rb:225:in call' puma (3.11.4) lib/puma/server.rb:632:in handle_request'
puma (3.11.4) lib/puma/server.rb:446:in process_client' puma (3.11.4) lib/puma/server.rb:306:in block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

Using Linux mint, rails version 5.2.0 and ruby version 2.4.1

Strong Params Changed

Hi @bodrovis .

I've found that rails has changed its way to permit a a field be on the whitelist.
Until now was:

application_controller.rb

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) << :name
  devise_parameter_sanitizer.for(:account_update) << :name
end

The new way that Devise has changed is:

def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
    devise_parameter_sanitizer.permit(:account_update, keys: [:name])
  end

I hope that this will help to get updated the tutorial.

Best!

Ruffeng

ActiveRecord:UnknownAttributeError Public_Activity Gem

When I try to create a new post, Public Activity intervenes and I'm unable to complete the request. I will post the controller_contents and stacktrace below.

class Post < ActiveRecord::Base
  include PublicActivity::Model

  tracked owner: Proc.new {|controller, model| controller.current_user ? controller.current_user : nil },
          photo: proc {|controller, model| model.photo },
          body: proc {|controller, model| model.body }

  has_many :comments, as: :commentable, dependent: :destroy
  belongs_to :user
  acts_as_commentable
  acts_as_votable
  default_scope -> { order(created_at: :desc) }
  validates :body, presence: true, length: {maximum: 150}
  validates :photo, presence: true #CarrierWave
  mount_uploader :photo, PhotoUploader
end

_activities.html.erb

<div class="col-md-4">
  <ul class="list-group">
    <% @activities.each do |activity| %>
        <li class="list-group-item">
          <span class="glyphicon glyphicon-<%= activity.key.match(/\.(.*)/)[1] %>"></span>
          <small class="text-muted"><%= activity.created_at.strftime('%H:%M:%S %-d %B %Y') %></small><br/>
          <strong><%= activity.owner ? activity.owner.username : 'Guest' %></strong>
          <%= render_activity(activity, display: :i18n) %>
          <% if activity.trackable %>
              "<%= link_to activity.trackable.body, post_path(activity.trackable) %>"
              "<%= link_to activity.trackable.photo, post_path(activity.trackable) %>"
          <% elsif activity.photo %>
              <span class="text-muted">"<%= activity.photo %>"</span>
          <% else %>
              with unknown post
          <% end %>
        </li>
    <% end %>
  </ul>
</div>

Posts_Controller.rb

class PostsController < ApplicationController
  before_action :authenticate_user!, except: [:show]
  before_filter :find_post, only: [:show, :like, :destroy]
  before_action :correct_user, only: [:destroy]
  respond_to :json, :html


  def index
    @user = User.find(params[:id])
    @post_items = Post.all.paginate(page: params[:page])
  end

  def show
    @post = Post.find(params[:id])
    @new_comment = Comment.build_from(@post, current_user.id, "")
  end

  def new
    @post = Post.new
    @maximum_length = Post.validators_on(:body).first.options[:maximum]
  end

  def create
    @user = current_user
    @post = @user.posts.build(post_params)

    if @post.save
      flash[:success] = "New Moment Posted"
      redirect_to @post
    else
      flash[:danger] = @post.errors.full_messages.to_sentence
      redirect_to root_url
    end
  end

  def destroy
    if @post.user == current_user
    @post.destroy
    redirect_to users_index_path
    flash[:success] = "Moment Deleted!"
    else
      redirect_to :back
      flash[:danger] = "Unable to delete Moment"
    end
  end

  def like
    @post = Post.find(params[:id])
    without_tracking do
      @post.liked_by current_user
    end
    @post.create_activity :like
    respond_to do |format|
      format.html { redirect_to :back }
      format.js { render layout: false }
    end
  end

  def unlike
    @post = Post.find(params[:id])
    @post.unliked_by current_user
    respond_to do |format|
      format.html { redirect_to :back }
      format.js { render layout: false }
    end
  end

  private
  def post_params
    params.require(:post).permit(:body, :photo)
  end

  def find_post
    @post = Post.find(params[:id])
  end

  def correct_user
    @post = current_user.posts.find_by(id: params[:id])
    redirect_to root_url if @post.nil?
  end

  def without_tracking
    Post.public_activity_off
    yield if block_given?
    Post.public_activity_on
  end
end

Stacktrace/Development log
ActiveRecord::UnknownAttributeError (unknown attribute 'photo' for PublicActivity::Activity.):
app/controllers/posts_controller.rb:27:in `create'

Cannot render console with content type multipart/form-dataAllowed content types: [#<Mime::Type:0x38b9878 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x38b8d68 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x38a1ff8 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]

action cable messaging system tutorial not working

I followed your path, but it says
uninitialized constant PersonalMessage::NotificationBroadcastJob

Extracted source (around line #9):

  after_create_commit do
    conversation.touch
    NotificationBroadcastJob.perform_later(self)
  end
  
end

load_matches! error

Hi.
I just found this code. Is awesome.
But, the live example is not working. I've cloned the repository and isn't working too.
I'm getting this error:

Faraday::ParsingError at /auth/steam/callback
757: unexpected token at '<title>Forbidden</title>

Forbidden

Access is denied. Retrying will not help. Please verify your
key=
parameter.'
the error show the "load_matches!" action.
The token is right.
Can u help me?

Doesn't work locally...

Just did git clone, bundle, rake db:create, migrate, rails s. It fires up nicely, but the automatic refresh between the two doesn't work.

How can i do if i have 2 devise users models ?

Hey

At the first time, thank you so much for this code 👍
I need something similar on my app but I have 2 devise models users : Campeur and Proprietaire.

How can I do to implement this code on my app with my 2 users models ?

Some precisions :
In my app, Campeur can engage the conversation to Proprietaire. Campeur can't engage the conversation to another Campeur. Proprietaire can respond only if one Campeur engage the conversation. Proprietaire cant engage the conversation with another Proprietaire.

Facebook failed

When I click "Facebook" nothing happens. Thanks for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.