https://github.com/dikshabittern/PostApplication
Friendship Request/Rejected in Mini FB App
1) create a friendship model
rails g model Friendship sender_id:integr receiver_id:integer status_id:integer
Next, rails db:migrate
show db table create friendship.rb
create_table :friendships do |t|
t.integer :sender_id
t.integer :receiver_id
t.integer :status_id, default: 1
t.timestamps
2) create a index page in friendship folder(friendship/index.html.erb) and add..
<div class="d-flex justify-content-center"><h1>List of Posts</h1></div><br>
<table class="table table-striped table-dark table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Profile Image</th>
<th>About</th>
<th>Actions</th>
</tr>
</thead>
3) create a friendship controller
rails g controller Friendships
4) How to use carrierwave in Project:-
=> gem 'carrierwave'
then bundle
=> Generating an Uploader
rails generate uploader Avatar
=> this should give you a file in:
app/uploaders/avatar_uploader.rb
=> how you can customize your uploader. It should look something like this:
class AvatarUploader < CarrierWave::Uploader::Base
storage :file
end
=> Add a string column to the model you want to mount the uploader by creating a migration:
rails g migration add_avatar_to_users avatar:string
rails db:migrate
=> Open your model file and mount the uploader:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
=> In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your
ApplicationController
:
class ApplicationController < ActionController::Base
# before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) do
|user_params|
user_params.permit({ roles: [] }, :email, :password, :password_confirmation,:first_name,:last_name)
end
devise_parameter_sanitizer.permit(:account_update) do
|user_params|
user_params.permit({ roles: [] }, :email, :password, :password_confirmation,:first_name,:last_name,:current_password)
end
end
end
No comments:
Post a Comment