Matt Jones wrote in post #1180799:
> On Thursday, 21 January 2016 22:21:37 UTC-6, Ruby-Forum.com User wrote:
>> class FollowsController < ApplicationController
>>
>>
>> <% end %>
>> the @user instead.
> The behavior you've described doesn't match the code. The `:locals => {
> :user => @user }` part of those render calls should have made `user`
> available in the partial. If you're switching to using the instance
> variable, make sure to remove all the references to the local variable
> (there's still one in the call to `user_follow_path`).
>
>
Can you help me re-write the solution?
<% if user_signed_in? %>
<% unless @user == current_user %>
<% if current_user.following?(@user) %>
<%= button_to('Stop Following',
user_follow_path(current_user.get_follow(@user)), :method => :delete,
:remote => true, class: 'btn btn-danger-outline') %>
<% else %>
<%= button_to('Follow', user_follows_path(@user), :remote =>
true, class: 'btn btn-success-outline') %>
<% end %>
<% end %>
<% end %>
create.js.erb
$('#follow_user').html('<%= escape_javascript(render :partial =>
"follows/follow_user") %>');
destroy.js.erb
$('#follow_user').html('<%= escape_javascript(render :partial =>
"follows/follow_user") %>');
__________________________________________________________________________
I'm getting this error now
ActionView::Template::Error (undefined method `id' for nil:NilClass):
1: <% if user_signed_in? %>
2: <% unless @user == current_user %>
3: <% if current_user.following?(@user) %>
4: <%= button_to('Stop Following',
user_follow_path(current_user.get_follow(@user)), :method => :delete,
:remote => true, class: 'btn btn-danger-outline') %>
5: <% else %>
6: <%= button_to('Follow', user_follows_path(@user),
:remote => true, class: 'btn btn-success-outline') %>
--------------------------------------------------------------------------
Can you try to come up with a better approach, and then show me how I
should solve this problem? I know that it's checking for the user id,
but the user may not be loaded yet.