Posts

Showing posts from February, 2022

odd And even number with yield

 def odd_number yield end (1..9).each_with_index do |odd_no,index|    if (index %2 ==0) then      odd_number { puts odd_no }   end end ========================================================================= def odd_number yield end arr = [] (1..9).each do |x| if x%2 !=0 arr << odd_number {x} end end p arr ========================================================================== def unique_names(names1, names2) arr = names1 + names2 aa = [] arr.uniq.each do |a| aa << a end   return aa end names1 = ["Ava", "Emma", "Olivia"] names2 = ["Olivia", "Sophia", "Emma"] puts(unique_names(names1, names2)) # should print Ava, Emma, Olivia, Sophia ========================================================================== def group_by_owners(files)   return nil end files = {   'Input.txt' => 'Randy',   'Code.py' => 'Stan',   'Output.txt' => 'Randy...

like and comment user

  1. search form-index <form>   <%= form_tag '/users', :method => 'get' do %>   <p>     <%= text_field_tag :title, nil, :placeholder=>"search users",:class=>"jjj" %>     <%= submit_tag "search"%>   </p> <% end %> </form> controller:- def index     if params[:title].present?       @users = User.where(" columnname  like ?", "%#{params[:title]}%")     else      @users = User.all     end   end search comment: form: <%= form_tag "/events/#{@event.id}", :method => 'get', remote: true do %>   <p>     <%= text_field_tag :name, nil, :placeholder=>"search comment",:class=>"" %>     <%= submit_tag "search"%>   </p> <% end %> controller: def show   if params[:name].present?       @comments = Comment.where("name like ...

device rails 7

1. Run Cammand     bundle add devise 2. Add Gem File gem "devise" 3. bundle install 4. rails g devise:install 5. rails g devise User 6. rake db:migrate 7. Application Controller Add This Line - before_action :authenticate_user! 8. Add devise.rb config.navigational_formats = ['*/*', :html, :turbo_stream]