The user index does not display delete links

22 views
Skip to first unread message

Jaimin Pandya

unread,
Jul 9, 2014, 1:02:09 AM7/9/14
to rubyonra...@googlegroups.com
I am using Ruby 2.0.0 and Rails 4.0.5. I follow "Ruby on Rails tutorial
by Michael Hartl".

I am trying to implement **"The destroy action"** (section 9.4.2).

Administrative users should see delete link

BUT

When i sign in, delete link is not appear. I can't able to solve this
issue.

Test suite run successfully.

>>My application.js file contain:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .

>> _user.html.erb:

<li>
<%= gravatar_for user, size: 52 %>
<%= link_to user.name, user %>
<% if current_user.admin? && !current_user?(user) %>
| <%= link_to 'delete', user, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
</li>

I attache user_pages_spec.rb file. Please find it.

How to fix this error?

Kind regards

Attachments:
http://www.ruby-forum.com/attachment/9872/user_pages_spec.rb


--
Posted via http://www.ruby-forum.com/.

dasibre

unread,
Jul 9, 2014, 10:05:56 AM7/9/14
to rubyonra...@googlegroups.com
If your tests are passing, try some debugging.
Check your current_user helper method make sure its working the way its supposed to work.

I would also check sessions to make sure the current user is available.

Javix

unread,
Jul 10, 2014, 3:49:31 AM7/10/14
to rubyonra...@googlegroups.com
How do you sign in , - as admin or not ? That's the question :)

Jaimin Pandya

unread,
Jul 10, 2014, 7:26:49 AM7/10/14
to rubyonra...@googlegroups.com
Serguei Cambour wrote in post #1152018:
> On Wednesday, July 9, 2014 7:02:09 AM UTC+2, Ruby-Forum.com User wrote:
>> When i sign in, delete link is not appear. I can't able to solve this
>> //= require_tree .
>> </li>
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
> How do you sign in , - as admin or not ? That's the question :)

No, First I will sign in. Then after sign in when i click on "Users".
After then Page generate of "All users". In that page "Delete" link
should appear

BUT

Delete link does not appear. How can I fix this problem?

Kind regards.

Jaimin Pandya

unread,
Jul 10, 2014, 7:30:40 AM7/10/14
to rubyonra...@googlegroups.com
dasibre wrote in post #1151967:
> If your tests are passing, try some debugging.
> Check your current_user helper method make sure its working the way its
> supposed to work.
>
> I would also check sessions to make sure the current user is available.

I am providing sessions_helper:

module SessionsHelper

.
.
.
.
.

def current_user=(user)
@current_user = user
end

def current_user
remember_token = User.digest(cookies[:remember_token])
@current_user ||= User.find_by(remember_token: remember_token)
end

def current_user?(user)
user == current_user
end

.
.
.
.
.

Javix

unread,
Jul 10, 2014, 7:44:19 AM7/10/14
to rubyonra...@googlegroups.com


On Wednesday, July 9, 2014 7:02:09 AM UTC+2, Ruby-Forum.com User wrote:
The 'delete' link will be displayed ONLY if the current user (i.e. the user which is actually signe in) is ADMIN:

if current_user.admin? 

So check the user credentials you use to sign in, - it is as easy as it is.

Jaimin Pandya

unread,
Jul 10, 2014, 9:57:36 AM7/10/14
to rubyonra...@googlegroups.com
> The 'delete' link will be displayed ONLY if the current user (i.e. the
> user
> which is actually signe in) is ADMIN:
>
> if current_user.admin?
>
> So check the user credentials you use to sign in, - it is as easy as it
> is.

Yes, It's as easy as it is after you giving me direction. I solved this
problem

Thank you.
Reply all
Reply to author
Forward
0 new messages