Melanie

Joined

1,520 Experience
6 Lessons Completed
0 Questions Solved

Activity

Posted in Get started with Rolify for roles

Hi Chris,

Please could you add an intro to rolify to your to do list.

I'm getting very confused with the documentation.

I want to have users in organisations who can have a role which extends to other members of the same organisation, so instance level roles seem to be what I'm looking for.

I'd love to see it done by a pro before I dive in.

Thanks very much
Mel

Posted in Comments With Polymorphic Associations Discussion

Hi Chris - I appreciate your efforts to help. The repo is private so I can't share it. Thanks anyway. Ill keep trying. It's been 3 years trying to grasp the basics and I'm still waiting for the penny to drop. Thanks anyway.

Posted in Comments With Polymorphic Associations Discussion

Should I go back to capital 'C' in comment for destroy? e.g.: <% if policy(Comment).destroy? %>

Posted in Comments With Polymorphic Associations Discussion

Hi, still no good. Each of the create, update and destroy methods are in the ordinary comments controller. When I try:

<% if policy(comment).update? %>

<%= button_to 'Edit', comments_path(comment), :method => :update, :class => 'btn btn-large btn-primary' %>

<% end %>

<% if policy(comment).destroy? %>

<%= button_to 'Delete', polymorphic_path([commentable, comment]), method: :delete, :class => 'btn btn-large btn-primary' %>

I get this error:

undefined method `comments_path' for #<#<class:0x007f9e26697c30>:0x007f9e1a6daff0>

On top of that, now my delete action doesnt work either (it did prior to this set of changes).

Posted in Comments With Polymorphic Associations Discussion

When I try:

<% if policy(comment).update? %>

<%= button_to 'Edit', comments_path(comment), :class => 'btn btn-large btn-primary' %>

<% end %>

I get this error:
Routing Error

No route matches [POST] "/articles/8/comments/30"

I'm baffled by the idea that update is defined in the same comments controller as delete. So far delete is working (using the polymorphic nested path), but update has errors.

Posted in Comments With Polymorphic Associations Discussion

Not sure how to check that. It's in the controller. I've followed the steps as set out in your tutorial. I'm not sure what I've messed up. I'll go back and watch the video again (take 30 might do it).

Posted in Comments With Polymorphic Associations Discussion

If I change the view so that it's:

<% commentable.comments.each do | comment | %>

<div class="well">

<%= comment.opinion %>

<div class="commentattributionname">

<%= comment.user.full_name %>

</div>

<div class="commentattributiontitle">

<%= comment.user.formal_title %>

</div>

<div class="commentattributiondate">

<%= comment.created_at.try(:strftime, '%e %B %Y') %>

</div>

<% if policy(comment).update? %>

<%= button_to 'Edit', polymorphic_path([commentable, comment]), :class => 'btn btn-large btn-primary' %>

<% end %>

<% if policy(comment).destroy? %>

<%= button_to 'Delete', polymorphic_path([commentable, comment]), method: :delete, :class => 'btn btn-large btn-primary' %>

<% end %>

</div>

then the delete still works (it did with 'Comment' instead of 'comment', but the update shows an error as:

No route matches [POST] "/articles/10/comments/29"

In my routes, I have:

resources :articles do

collection do

get 'search'

end

resources :comments, module: :articles

end

resources :comments, only: [ :update, :destroy]

Posted in Comments With Polymorphic Associations Discussion

Hi Chris - when I try that, I get this error: Pundit::NotDefinedError in Articles#show

Showing //app/views/comments/_display.html.erb where line #25 raised:

unable to find policy of nil

Also, It's strange that the form of expression the way I had it works in delete, but not in update

Posted in Comments With Polymorphic Associations Discussion

The error log says:
Completed 500 Internal Server Error in 56ms (ActiveRecord: 28.7ms)

ActionView::Template::Error (undefined method `user' for #<class:0x007f9e1a734af0>):

22: <%= comment.created_at.try(:strftime, '%e %B %Y') %>

23: </div>

24:

25: <% if policy(Comment).update? %>

26: <%= button_to 'Edit', polymorphic_path([commentable, comment]), :class => 'btn btn-large btn-primary' %>

27: <% end %>

28: <% if policy(Comment).destroy? %>

app/policies/comment_policy.rb:13:in `update?'

app/views/comments/_display.html.erb:25:in `block in _app_views_comments__display_html_erb___34367520595054411_70158511210960'

app/views/comments/_display.html.erb:12:in `_app_views_comments__display_html_erb___34367520595054411_70158511210960'

app/views/articles/show.html.erb:68:in `_app_views_articles_show_html_erb__2619839868106814513_70158550563960'

Posted in Comments With Polymorphic Associations Discussion

Hi - what part would that be?
def set_article

@article = Article.find(params[:id])

authorize @article

end

Posted in Comments With Polymorphic Associations Discussion

Yes - my articles controller update action has:

def update
# before_action :authenticate_user!
authorize @article
respond_to do |format|
# if @article.update(article_params)
# format.json { render :show, status: :ok, location: @article }
# else
# format.html { render :edit }
# format.json { render json: @article.errors, status: :unprocessable_entity }
# end
# end
if @article.update(article_params)
format.json { render :show, status: :ok, location: @article }
else
format.json { render json: @article.errors, status: :unprocessable_entity }
end
format.html { render :edit }
end
end

Posted in Comments With Polymorphic Associations Discussion

Hi Chris, I'm still struggling along in trying to get this set up. My current issue is with my comments policy update function. Your tutorial shows how to define update as set out below (which I have tried in both my article policy and my comment policy:

Article Policy:

def update?

#user && user.article.exists?(article.id) -- I have also tried this on this suggestion of someone on stack overflow).

user.present? && user == article.user

end

Comment Policy:

def update?

user.present? && user == comment.user

end

I keep getting a controller action error which says: undefined method `user' for #<class:0x007f9e24fa7cf0>

It highlights the update definition. Has something changed in pundit that requires a different form of expression for this update function? Can you see what might have gone wrong? Thanks very much

Posted in Comments With Polymorphic Associations Discussion

Thanks so much Chris.

Posted in Comments With Polymorphic Associations Discussion

Hi Chris. Thanks very much for the response. I tried adding this to my routes:

resources :comments, only: [ :destroy]

and this to my existing comments controller (which only had the create method in it - per your tutorial)

def destroy
@comment.destroy
respond_to do |format|
format.html { redirect_to data_url }
format.json { head :no_content }
end
end.

When I try this, I get an error that says:
undefined method `destroy' for nil:NilClass

Any ideas on what's gone awry?

Posted in Comments With Polymorphic Associations Discussion

I am trying to add a delete comment button to this. But it is sending me to the articles controller destroy action. Please can you add how to add a delete button to the comment? I'm stuck. Thanks very much!

I am trying to follow along with this but I get this error when I try Article.reindex (equivalent of Question.reindex)

NoMethodError: undefined method `reindex'

In the console, I try: Article.reindex

It returns:
NoMethodError: undefined method `reindex' for Article (call 'Article.connection' to establish a connection):Class

Also, when I try to run the local host, I get this error:

Index missing - run Article.reindex
# GET /articles.json
def index
@articles = Article.search(params[:q])
end

# GET /articles/1

For me:

def index
query = params[:q].presence || "*"
@articles = Article.search(query)
end

gives this error:

MissingIndexError in ArticlesController#index
Index missing - run Article.reindex

My key difference is that:

I use simple form for forms, so i made a new partial to insert in my articles index as:

<%= simple_form_for(@article) do |f| %>

<%=f.text :q, :nil, placeholder: "Search" %>

<% end %>

TOTAL NUMPTY: I DIDN'T INSTALL THE GEM. SORRY!