Open Oppenheimer1 opened 9 years ago
@Oppenheimer1 you are specifying Speed : <%= rating_for , "speed", :star => 10 %>
although "speed"
dimension is not added to the line ratyrate_rateable "fun"
in your Comment model, so please change it to ratyrate_rateable "fun", "speed"
.
Also notice that you didn't pass @comment
to rating_for
method.
Speed : <%= rating_for , "speed", :star => 10 %>
I updated the model to have:
class Comment < ActiveRecord::Base
belongs_to :article
ratyrate_rateable "fun", "speed"
end
And the view _comment.html.erb to
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<p>
Speed : <%= rating_for @comment, "fun", :star => 10 %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.article, comment],
method: :delete,
data: { confirm: 'Are you sure?' } %>
</p>
But I'm getting the error:
Showing app/views/comments/_comment.html.erb where line #12 raised:
undefined method `average' for nil:NilClass Extracted source (around line #12):
9
10
11
12
13
14
15
</p>
<p>
Speed : <%= rating_for @comment, "fun", :star => 10 %>
</p>
<p>
Could you use an upstream version of the gem, just change your Gemfile as follows:
gem 'ratyrate', github: 'wazery/ratyrate'
Then run:
bundle update
I updated the gem and didn't change anything else but I'm getting the following error:
NoMethodError in Articles#show Showing app/views/comments/_comment.html.erb where line #12 raised:
undefined method `average' for nil:NilClass Extracted source (around line #12): 9 10 11 12 13 14 15
Speed : <%= rating_for @comment, "fun", :star => 10 %>
I have my models Articles and Comments with the commenter having the ability to comment on the Articles but not make edits to the Articles so I have my user model as Articles. I'm not sure What I'm doing wrong.
I don't understand how your user model is replaced by article, you need to make the entity that will do the comment have ratyrate_rater
helper in its model, which is the user in most of the cases.
I don't have a user class. I have Articles which I want to be rated using the star rating and Comments in which a commenter can comment on each of the Articles. I think this is making it more complicated but I don't know how to reconfigured my models to work with the ratyrate gem.
Sorry for being late in replying, I got some sleep. You mentioned a "commenter" what is that entity actually in your models, there must be a user entity which will create new articles comments, your implementation is not clear for me.
I see in your code the following line <%= comment.commenter %>
what is the commenter? I don't see any association related to it.
Also in your comment you say
"I have Articles which I want to be rated using the star rating"
So the article is what will be rated not the comment as you write in your code?
Please if you can give me some more code snippets or access to your source code it would be better.
I pushed the source code up to github:
I will open a PR against your app repo when everything is wired up.
Is there anything else I need to upload or is the source code ok.
It's ok.
I opened a PR, please check it.
Apologies I had uploaded the wrong version. The correct one is at:
https://github.com/Oppenheimer1/test_2 I made the change to the _comment.html.erb but I'm still getting an error. Sorry for the confusion.
I've edited your code and created a pull request. The problem was there was no current_user method available for rating_for to work with. Please see the changes in articles_controller.rb However it's easier to use Devise to create the authentication. You can find the pull request https://github.com/Oppenheimer1/test_2/pull/1
I have my models as:
And
And in my view
_comment.html.erb
I haveBut I'm getting an error message:
NoMethodError in Articles#show
Showing app/views/comments/_comment.html.erb where line #12 raised:undefined method `average' for nil:NilClass Extracted source (around line #12): 9 10 11 12 13 14 15
<%= rating_for @comment, "fun" %>
Please help.