Lee Terng Gio

Joined

2,260 Experience
4 Lessons Completed
1 Question Solved

Activity

I've tried to use if else statement, and display a link next to the message, when I submit a message, the link won't display, and I have to refresh the page. It seems like if else statement doesn't work in actioncable.

Posted in Group Chat with ActionCable: Part 7 Discussion

I've tried to use if else statement, and display a delete link next to the message, when I submit a message, the delete link won't display, and I have to refresh the page. It seems like if else statement doesn't work in actioncable.

Posted in How to use Hotwire in Rails Discussion

How to add auto scrolling when adding a post?

Posted in Hotwire Modal Forms Discussion

I have two models, Post and Comment, the validation message doesn't show up when creating a comment. the rest are working fine except the validation doesn't show up.

Posted in How to use Hotwire in Rails Discussion

I have an issue when I submit an empty for the second time. If I submit the empty field for the first time, the validation displays, then if I submit again with empty field, the submit button is then disabled. How to solve that?

Posted in How to initialize datepicker in stimulus controller?

I'm using datepicker and turbo frame. The datepicker is broken when the frame is replaced. I'm doing turbo:load in javascript file, it works when navigating between pages, but it will be broken when the form is replaced. I'm thinking to initialize datepicker in stimulus controller but I'm not familiar with stimulus. There aren't many documentation on stimulus, any idea?

Posted in How to use Hotwire in Rails Discussion

I have a datepicker in my form, and it's broken when the form is replaced. How to solve that issue?

I'm creating a User, Role and UserRole. A user can create a list of roles, and from the new user form, there is a nested form which populate a list of roles created, then the user able to select a role and associated with the new user. I'm able to create a list of roles, but facing problem when creating a nested form in the new user view file.

Here are the models, kindly advise me if relationships are correct.

class User < ApplicationRecord
  has_one :user_role
  has_one :role, through: :user_role
end
class Role < ApplicationRecord
  has_many :user_role
  has_many :user, through: :user_role
end
class UserRole < ApplicationRecord
  belongs_to :user
  belongs_to :role
end

User controller. I'm not sure if my controller is correct:

def new
  @user = User.find_by_id(params[:id])
    @user = @current_user.account.users.new
  @user = @current_user.build_user_role
end

def create
    @user = User.find_by_id(params[:id])                
    @user = @current_user.account.users.create_with_password(user_params)
if @user.save
  redirect_to users_path
else
  render 'new'
end

private
def user_params
  params.require(:user).permit(:id, :email, :password, :password_confirmation, :admin, :owner, user_role_attributes: [:user_id, :role_id])
end

end

Below is new user form:

<%= form_for(@user, remote: true) do |f| %>

<%= f.text_field :email, class: "form-control", autofocus: true, autocomplete: "off" %>
<%= f.check_box :admin, class:"checkbox" %>
<%= f.check_box :owner, class:"checkbox" %>

<%= f.fields_for :user_role do |ff| %>
<!-- I don't know how to create a select dropdown to populate a list of roles that have been created -->
<% end %>             

<%= f.button "Create",  class: "btn btn-success" %>

<% end %>

I'm implementing Switchery button in my Rails app and Turbolinks is on. When I navigate to another page, and then click the back button, the button is being duplicated.

Here is my Javascript code:

$(document).on('turbolinks:load', function() {
var elem = document.querySelector('.js-switch');
var switchery = new Switchery(elem, {className:"switchery switchery-small"});
});

Html view:
<b>Assign as administrator?<span> <%= f.check_box :admin, class:"js-switch" %></span></b>

Screenshot: ![https://i.stack.imgur.com/ePJdk.png]

So how can i handle this problem ?

I'm implementing Switchery button in my Rails app and Turbolinks is on. When I navigate to another page, and then click the back button, the button is being duplicated.

Here is my Javascript code:

$(document).on('turbolinks:load', function() {
var elem = document.querySelector('.js-switch');
var switchery = new Switchery(elem, {className:"switchery switchery-small"});
});

Html view:
<b>Assign as administrator?<span> <%= f.check_box :admin, class:"js-switch" %></span></b>

Screenshot: ![https://i.stack.imgur.com/ePJdk.png]

So how can i handle this problem ?

I'm implementing Switchery button in my Rails app and Turbolinks is on. When I navigate to another page, and then click the back button, the button is being duplicated.

Here is my Javascript code:

$(document).on('turbolinks:load', function() {
var elem = document.querySelector('.js-switch');
var switchery = new Switchery(elem, {className:"switchery switchery-small"});
});

Html view:
<b>Assign as administrator?<span> <%= f.check_box :admin, class:"js-switch" %></span></b>

Screenshot: ![https://i.stack.imgur.com/ePJdk.png]

So how can i handle this problem ?

Posted in Switchery toggle button duplicated using Turbolinks

I'm implementing Switchery on my Rails app, and I'm also using Turbolinks. Everything works fine and the switchery is working except when I click to another page and then click the back button, the switchery icon actually duplicated and show twice. How do I destroy when navigating back to the page?

Here is the JavaScript code:

var ready;
ready = function() {
    var elem = document.getElementById('js-switch');
    var switchery = new Switchery(elem, {className:"switchery switchery-small"});

};
$(document).on('turbolinks:load', ready);

I'm implementing Switchery on my Rails app, and I'm also using Turbolinks. Everything works fine and the switchery is working except when I click to another page and then click the back button, the switchery icon actually duplicated and show twice. How do I destroy when navigating back to the page?

Here is the JavaScript code:

var ready;
ready = function() {
    var elem = document.getElementById('js-switch');
    var switchery = new Switchery(elem, {className:"switchery switchery-small"});

};
$(document).on('turbolinks:load', ready);

Posted in Group Chat with ActionCable: Part 5 Discussion

Hi Chris, I don't want to use Turbolinks in my app. Is there any way to replace the code?

Posted in Rails actioncable registered connection issue

I'm implementing ActionCable in my Rails app. I'm facing an issue with Registered Connection error. I'm using MongoID in my Rails app.

Here is my connection.rb

module ApplicationCable
  class Connection < ActionCable::Connection::Base
   identified_by :current_user

def connect
  self.current_user = find_verified_user
  logger.add_tags "ActionCable", "User #{current_user.id}"
end

protected

def find_verified_user
 current_user = User.find_by(cookies.signed[:user_id])
  if current_user
    current_user
  else
    reject_unauthorized_connection
  end  
end

  end
end

Here is my logs

Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
MONGODB | [52] localhost:27017 #1 | dashtree_development.find | STARTED | {"find"=>"users", "filter"=>{"_id"=>BSON::ObjectId('5e3f6782f026752069ba5c21')}, "lsid"=>{"id"=><BSON::Binary:0x47104983206780 type=uuid data=0xac31709d0cea4a74...>}}
MONGODB | [52] localhost:27017 | dashtree_development.find | SUCCEEDED | 0.000s
[ActionCable] [User 5e3f6782f026752069ba5c21] Registered connection (#<User:0x00007f09400c49c8>)
[ActionCable] [User 5e3f6782f026752069ba5c21] ChatroomsChannel is transmitting the subscription confirmation
[ActionCable] [User 5e3f6782f026752069ba5c21] ChatroomsChannel is streaming from chatrooms:5e3f6782f026752069ba5c21

There is an issue with Registered connection (#<User:0x00007f09400c49c8>). I'm still unable to find a solution on this.

Posted in Issues with JQuery AtWho

I getting undefined value.
Is it possible you make free for this episode? Would be appreciated.

Posted in Attach image to summernote and send email

I recently implement email in my rails app. I'm using summernote to create email templates and save it. Everything works fine. I can upload image to the editor and save it to database. But when I send the email template, the image in the email that I'd received is broken. I didn't use any uploader to handle the image uploaded, the image was encoded in Base64, so how do I fix this?

My mailer.rb
def message_send(candidate_mail)

@candidate_mail = candidate_mail

mail(

  to: "#{@candidate_mail.to}",

  from: "#{@candidate_mail.from}",

  subject: "#{@candidate_mail.subject}",

  body: "#{@candidate_mail.body}",

  content_type:  "text/html",

  important: true,

  inline_css: true,


  )

end

I can send the email, the problem is the image is broken in the received email. I have seen documentation of how to add attachments to email, but that's not what I want because those are normally refer to public file or something or they hard code it. I use summernote to save the text and image, and they render properly in view, but the image shows broken when it's being sent out as an email. For your information, the image is encoded in Base 64 when save into database.

I recently tried to implement summernote to my rails app. I can send email and everything works fine. But I want to upload image and send the email, but the email received shows that the image was broken. How do I fix it?

The email that attached with uploaded image doesn't need to be saved into database. I just want to send the email.

My mailer.rb
def message_send(candidate_mail)
@candidate_mail = candidate_mail
mail(
to: "#{@candidate_mail.to}",
from: "#{@candidate_mail.from}",
subject: "#{@candidate_mail.subject}",
body: "#{@candidate_mail.body}",
content_type: "text/html",
important: true,
inline_css: true,

)
end