madchatter / mad_chatter

Mad Chatter is a fun, easy to customize chat server written in Ruby utilizing HTML 5 Server Sent Events
http://madchatter.github.io/
MIT License
12 stars 6 forks source link

rails 4 is stable #1

Closed nurettin closed 11 years ago

nurettin commented 11 years ago

Hi, I am trying to make a rails4 branch for mad_chatter so I can use it in my brand new rails 4 project.

I first fixed the rails3 dependency in gemspec, then I got:

/home/nurettin/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/mapper.rb:191:in `normalize_conditions!': You should not use the `match` method in your router without specifying an HTTP method. (RuntimeError)`

Not knowing where the error originated from, I edited config/routes file and changed session destroy path:

delete 'logout' => 'sessions#destroy'

But I still get the same error. Is there something I need to fix in Faye, perhaps?

nurettin commented 11 years ago

I got past the error by including

gem 'faye-rails' 

in my project's Gemfile after finding out about this commit

nurettin commented 11 years ago

Now this line in users_controller

before_filter :require_authenticated_user, except: [:new, :create]

is redirecting me to mad_chatter's login page, which is OK. The problem is, I already have a devise User model in my project in the root namespace. When I try to login, because of this line in mad_chatter's sessions_controller#create:

if user = User.authenticate(params[:username], params[:password])

I get

NoMethodError in MadChatter::SessionsController#create
undefined method `authenticate' for #<Class:0x00000006fa25e8>
nurettin commented 11 years ago

I got past this problem by adding self.authenticate method to my own User model:

def self.authenticate(username, password)
  if user = find_by_email(username)
    user if user.valid_password?(password)
  end
end

I guess this is a temporary workaround for the task Allow user login to use main Rails app user accounts.

nurettin commented 11 years ago

Now I'm getting:

RuntimeError in MadChatter::RoomsController#index
`attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one.
nurettin commented 11 years ago

I got past that by just adding gem 'protected_attributes' to my project for now. Normally, you would remove attr_accessible from all models and whitelist parameters at controller level like so:

params.permit(room: [:name, :title])
nurettin commented 11 years ago

Now I'm getting:

Mysql2::Error: Table 'myapp_development.mad_chatter_rooms' doesn't exist: SELECT `mad_chatter_rooms`.* FROM `mad_chatter_rooms`

Of course, mad_chatter migrations are not done. Not sure how to do them properly.

nurettin commented 11 years ago

I got past this by listing rake -T and running

rake mad_chatter:install:migrations db:migrate
nurettin commented 11 years ago

Now I'm getting this error when rendering mad_chatter application layout.

require_tree argument must be a directory
  (in /home/nurettin/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mad_chatter-d353893e10ef/app/assets/javascripts/mad_chatter/application.js:19)

At the line

<%= javascript_include_tag "mad_chatter/application" %>

These are the require lines in application.js

//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require bootstrap
//= require ./mad_chatter
//= require_tree ../../templates/mad_chatter
//= require_tree ./models
//= require_tree ./collections
//= require_tree ./views
//= require_tree ./routers
//= require_tree .
nurettin commented 11 years ago

I got past this by changing the line

//= require_tree ../../templates/mad_chatter

to

// require_tree ../../templates/mad_chatter
nurettin commented 11 years ago

I managed to enter the lobby and create a room, but when I sent a message it said my model doesn't have username which I got past by adding

def username
  email
end

to my devise model.

nurettin commented 11 years ago

Now I'm getting

ActiveRecord::RecordNotFound in MadChatter::RoomsController#show
Couldn't find MadChatter::User with id=1

Which means mad_chatter is finally trying to use its own model to find the room users.

nurettin commented 11 years ago

I hacked around the issue saying if ::User exists, MadChatter::User is a ::User. Otherwise it is defined.

module MadChatter
  if defined?(::User)
    class User< ::User

    end
  else
    class User < ActiveRecord::Base 
    # ...
nurettin commented 11 years ago

Now I see a basic chat application. No refresh, no long polling, no web sockets. O_o

andrewhavens commented 11 years ago

Hello @nurettin! Thanks for working through some of these issues. I haven't had a chance to try it out with Rails 4 so I'm not surprised there may be some issues. This version of Mad Chatter (Rails engine) is very much a work in progress and there may be some major areas that still need implementing.

Some thoughts on your work so far:

If there are any areas that you'd like to work on, let me know and I'll leave those to you.

Thanks! Andrew

andrewhavens commented 11 years ago

@nurettin I wanted to let you know that I made a lot of big updates, and added support for Rails 4. I switched from using Faye to simply implementing Server Sent Events because there is better browser and server support for SSE and it's easier to implement. The performance will be just as good as Web Sockets. I still need to implement the User authentication, but I have created a separate issue to track the progress on that.

wanbok commented 11 years ago

This issue is still alive.

wanbok commented 11 years ago

I hacked around the issue having one more session when it has devise session.

delete this code :

def current_user
  if id = session[:user_id]
    User.find(id)
  end
end

and edit this code

def require_authenticated_user
  unless current_user.present?
    redirect_to mad_chatter.auth_login_path
  end
end

to

def require_authenticated_user
  unless user_signed_in?
    redirect_to mad_chatter.auth_login_path
  end
end
wanbok commented 11 years ago

When i send a message, i got an error that Redis::CannotConnectError in MadChatter::MessagesController#create

I got past this problem.

delete $redis.publish "madchatter:rooms:#{current_room.id}", @message.to_json at message_controller.rb:45

or

install redis. but it seems to be unnecessary

andrewhavens commented 11 years ago

@wanbok Regarding devise, let's move this to a separate issue. Regarding Redis, yes, you will need to have Redis installed. It will be a requirement. I should mention this in the readme.