Skip to content

Loading…

Installation issues. #25

Open
XeroCodeIT opened this Issue · 8 comments

4 participants

@XeroCodeIT

I have followed the instructions and have tried the installation a couple of times now.

Steps I've done:
Added plugin to gemfile, ran bundle install
rails generate simple_private_messages:model User Pmessage
Added this line to user.rb : has_private_messages :class_name => "Pmessage"
rails generate simple_private_messages:scaffold User Pmessage
Uncommented this line in pmessage.rb : attr_accessor :to

I then added this to my routes.rb :
match '/pmessages', to: 'pmessages#index'

Accessing /pmessages results in this error message:
ActiveRecord::RecordNotFound in PmessagesController#index
Couldn't find User without an ID
Rails.root: /home/user/RoR/railsapp
app/controllers/pmessages_controller.rb:59:in `set_user'

pmessages controller, set_user method:
private
def set_user
@user = User.find(params[:user_id])
end

Changing that line to @user = User.find(1) and accessing /pmessages results in this error message:

Showing /home/user/RoR/railsapp/app/views/pmessages/_inbox.html.erb where line #26 raised:
undefined method `login' for #User:0xab4dc3c
Extracted source (around line #26):

Any ideas on what's wrong and how to fix it?

Using Rails 3.2.3

@safarista
Collaborator
@XeroCodeIT

I use Devise.

I added an alias in my user.rb model:
alias_attribute :login, :name
This fixed the "undefined login method" problem.

I also changed
@user = User.find(params[:user_id])
to
@user = current_user

Now I can access inbox and sent messages, but can't access /users/1/pmessages/new to create a new message. Error message I get is:

undefined method `error_message_on' for #<#Class:0x926d780:0xa017228>

Extracted source (around line #5):
2:


3: To:

4: <%= f.text_field :to %>
5: <%= error_message_on @pmessage, :to %>
6:


7:


8: Subject:

@safarista
Collaborator
@XeroCodeIT

attr_accessor :to was already uncommented in user.rb

If I navigate to http://localhost:3000/users/1/pmessages/1 to show a message (which I added by seeding) and then click on the "Reply" button, it takes me to http://localhost:3000/users/1/pmessages/new?reply_to=1 .

Error message I get is:
undefined method `error_message_on' for #<#Class:0x926d780:0xaf2e07c>
Extracted source (around line #5):

2:


3: To:

4: <%= f.text_field :to %>
5: <%= error_message_on @pmessage, :to %>
6:

It's the same message I get when I access simply http://localhost:3000/users/1/pmessages/new.

@safarista
Collaborator

How many users do yo have in your database? And are you replying/sending message to anyone?

Try and use your own data i.e. users that are on your system. Using device I presume you setup a user authentication maybe on a different model i.e. Person.

You will have to provide a lot more info here. It does not look like you are sending messages to anyone.

@safarista
Collaborator

A typical example would be:

I am users/1
I go to users/2 and click on a a link "Send me a PMessage " which looks like <%= link_to "Send me a PMessage ", new_user_pmessage_path(@user, :to => @user.id) NOTE this is a new message to user 2

That would give me a url like http://localhost:3000/users/1/pmessages/new?to=2

@isasi88

I'm getting the same error:

undefined method `error_message_on' for #<#Class:0x007f8736aa9230:0x007f8738360878>

Extracted source (around line #5):

2:


3: To:

4: <%= f.text_field :to %>
5: <%= error_message_on @message, :to %>
6:


7:


8: Subject:

I'm algo using Devise gem

@jongilbraith

The generators are out of date, error_message_on was dropped in Rails 3.

It's more common to roll your own thesedays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.