Note that there are some explanatory texts on larger screens.

plurals
  1. POUnique friendship help needed Rails 3
    primarykey
    data
    text
    <p>I need help about friendship uniqueness and add to friend links my routes.rb:</p> <pre><code>devise_for :users resources :users, only: [:index, :show] do resources :friendships, only: [:create, :destroy] end </code></pre> <p>my User model :</p> <pre><code>class User &lt; ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :username # attr_accessible :title, :body has_many :topics has_many :posts has_many :friendships has_many :friends, :through =&gt; :friendships has_many :inverse_friendships, :class_name =&gt; "Friendship", :foreign_key =&gt; "friend_id" has_many :inverse_friends, :through =&gt; :inverse_friendships, :source =&gt; :user end </code></pre> <p>my friendship model :</p> <pre><code>class Friendship &lt; ActiveRecord::Base attr_accessible :friend_id, :user_id belongs_to :user belongs_to :friend, :class_name =&gt; "User" end </code></pre> <p>friendships_controller.rb:</p> <pre><code>class FriendshipsController &lt; ApplicationController before_filter :authenticate_user! def create @friendship = current_user.friendships.build(:friend_id =&gt; params[:friend_id]) if @friendship.save flash[:notice] = "Arkadaşlara eklendi." redirect_to root_url else flash[:error] = "Arkadaşlara Eklenemiyor." redirect_to root_url end end def destroy @friendship = current_user.friendships.find(params[:id]) @friendship.destroy flash[:notice] = "Arkadaşlarımdan kaldırıldı." redirect_to current_user end end </code></pre> <p>users_controller.rb:</p> <pre><code>class UsersController &lt; ApplicationController before_filter :authenticate_user! def index @users = User.all end def show @user = User.find(params[:id]) @topics = @user.topics.paginate(page: params[:page]) @friendship = @user.friendships.build(:friend_id =&gt; params[:friend_id]) @friendships = @user.friendships.all end end </code></pre> <p>This is my friend add link :</p> <pre><code> &lt;h1&gt; &lt;%= @user.username %&gt; &lt;/h1&gt; &lt;%= link_to "Arkadaşlarıma Ekle", friendships_path(:friend_id =&gt; @user), :method =&gt; :post,class: "btn btn-large btn-primary" %&gt; </code></pre> <p>And I cant find the correct path for showing users as friends.</p> <pre><code>&lt;% for friendship in @friendships %&gt; &lt;%= link_to friendship.friend.username, '#' %&gt; (&lt;%= link_to 'Sil', friendship, :method =&gt; :delete %&gt;) &lt;% end %&gt; </code></pre> <p>Can anyone help me ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload