может любезно посоветуйте мне, как определить @friend
в моем контроллере. Я определил @friend
как @friend = User.find_by_email(params[:id])
, но это не подбирается. если можно было бы любезно объяснить я был бы очень благодареннеопределенный метод `id 'для nil: NilClass - ссылочная ассоциация - рельсы 4
я в настоящее время получаю эту ошибку
undefined method `id' for nil:NilClass
просмотров/карты/show.html.erb
<div class="current_connection">
<%= friendship_status(@user, @friend) %>
</div>
in my cards_controller.rb
class CardsController < ApplicationController
before_action :set_card, only: [:show, :edit, :update, :destroy]
before_filter :setup_friends
def index
...
end
def show
end
def new
...
end
...
private
def set_card
@card = Card.find(params[:id])
end
def setup_friends
@user = User.find(current_user.id)
@friend = User.find_by_email(params[:id])
end
def card_params
params.require(:card).permit(:title, :event_id)
end
end
frienship_helper.rb
module FriendshipsHelper
# Return an appropriate friendship status message.
def friendship_status(user, friend)
friendship = Friendship.find_by_user_id_and_friend_id(user.id, friend.id)
return "#{friend.firstname} is not in your network (yet)" if friendship.nil?
case friendship.status
when 'requested'
"#{friend.firstname} wants to connect with you"
when 'pending'
"You have requested to connect with #{friend.firstname}"
when 'accepted'
"#{friend.firstname} is in your network"
end
end
end
маршруты
Rails.application.routes.draw do
devise_for :users
resources :users do
resources :events
end
resources :events do
resources :cards
end
end