Skip to content

Instantly share code, notes, and snippets.

@abhianair
abhianair / .erb
Last active October 17, 2018 05:36
Count the number of posts created by a user ( current user ) in RoR
<h1>Posts Created: <span class="dashspan"><%= @app = current_user.posts.count %></span></h1>
@abhianair
abhianair / .rb
Created October 29, 2018 12:36
config code for email verification in config>>environment>>development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: "localhost:3000" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
user_name: "username@gmail.com",
password: "password",
domain: "localhost:3000",
address: "smtp.gmail.com",
port: 587,
@abhianair
abhianair / .erb
Created October 30, 2018 04:39
take a username out of user's email in ERB
<%= @posts.user.email.split('@')[0].capitalize %>
@abhianair
abhianair / .rb
Created November 1, 2018 04:51
Rails console - Maiking a user admin
@user = User.find(id)
@user.admin = true
@user.save!
@abhianair
abhianair / .rb
Created November 1, 2018 06:24
Creating a Post by a user - Rails
@post.user = current_user
@abhianair
abhianair / .erb
Created November 2, 2018 06:55
Multiple Check Box A probable failed code but can be compiled successfully by perfection
<div class="field">
<%= label_tag 'days_monday', 'Monday' %>
<%= check_box_tag 'business_pro[days][]','Monday',checked('pop'), id: 'days_monday' %>
<%= label_tag 'days_tuesday', 'Tuesday' %>
<%= check_box_tag 'business_pro[days][]','Tuesday',checked('pop'), id: 'days_tuesday' %>
<%= label_tag 'days_wednesday', 'Wednesday' %>
<%= check_box_tag 'business_pro[days][]','Wednesday',checked('pop'), id: 'days_wednesday' %>
</div>
@abhianair
abhianair / model.rb
Created November 2, 2018 08:23
Adding Input from Multi Select Box and converting to a string a store it in a single column in a database - Rails
def days=(value)
return super value.reject!(&:blank?).join(", ") if value.is_a?(Array)
super
end
@abhianair
abhianair / confirmation_instruction.html.erb
Created November 12, 2018 04:38
Confirmation mail sent from tenant
<p>Welcome <%= @email.split('@')[0].capitalize %>!</p>
<p>Your Mail is Verified ! You can procees your signing Up By clicking the link below.</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, subdomain: Apartment::Tenant.current) %></p>
@abhianair
abhianair / controller.rb
Created November 16, 2018 11:08
Enter Subdomain name inside input field and redirect to its domain if the subdomain present.
def proceed
@domain_from_form = params[:search][:q]
@domain_search = User.pluck(:subdomain)
@domain_present = @domain_search.include? @domain_from_form
if @domain_present == true
redirect_to "http://#{@domain_from_form}.lvh.me:3000/accounts/sign_in"
else
redirect_to resub_index_path
end
end
@abhianair
abhianair / application_controller.rb
Created November 20, 2018 07:09
authenticate any of the user model using devise - Rails
def authenticate_any!
if user_signed_in?
true
else
authenticate_account!
end
end