Closed nurettin closed 11 years ago
I got past the error by including
gem 'faye-rails'
in my project's Gemfile after finding out about this commit
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>
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.
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.
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])
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.
I got past this by listing rake -T
and running
rake mad_chatter:install:migrations db:migrate
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 .
I got past this by changing the line
//= require_tree ../../templates/mad_chatter
to
// require_tree ../../templates/mad_chatter
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.
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.
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
# ...
Now I see a basic chat application. No refresh, no long polling, no web sockets. O_o
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:
faye-rails
gem is very different than the faye
gem. Although, using faye-rails
may be a good way to go.strong_parameters
gem since it's the new default in Rails 4, rather than adding protected_attributes
which is the older approach.current_user
in order to determine if the user has been authenticated. The MadChatter::User (or mad_chatter_users table rather) would still be used to keep track of Mad Chatter specific user information like display name or basic preferences, so it would store a reference to the original ::User id
field. You would also be able to configure the routes to send users in order to authenticate or create accounts. Not sure if you have any interest in implementing something like this...faye-rails
to see if it works well enough for the implementation that I had in mind.If there are any areas that you'd like to work on, let me know and I'll leave those to you.
Thanks! Andrew
@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.
This issue is still alive.
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
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
@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.
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:
Not knowing where the error originated from, I edited config/routes file and changed session destroy path:
But I still get the same error. Is there something I need to fix in Faye, perhaps?