jeudi 30 avril 2020

How to upload xls file into S3 bucket using ruby on rails

In our rails 6 project I want to upload excel file into S3 bucket and send file link to email and provide download xls feature from email. Please help me.

mercredi 29 avril 2020

Localhost:3000 is not working for Ruby on Rails on windows

Hi I'm new to ruby and my localhost:3000 is not working on my windows machine enter image description here

I did exactly the way the guy has done in this video But it worked his this machine whereas mine did not and then I tried many different ways that I got on the internet ut it all proved to be a waste of time. Please help me!! I'm stuck with this from like last 5 days and haven't made any progress

mardi 28 avril 2020

Parsing multiple .log files to get a string name

File1.log Result for scripts as follows {"Script 1"=>{"expected"=>"Pass", "actual"=>"Pass", "result"=>true},

"Script 2"=>{"expected"=>"Fail", "actual"=>"Pass", "result"=>false}

-----


Result for scripts as follows {"Script 3"=>{"expected"=>"Pass", "actual"=>"Pass", "result"=>true}, "Script 4"=>{"expected"=>"Fail", "actual"=>"Pass", "result"=>false}

File2.log Result for scripts as follows {"Script 1"=>{"expected"=>"Pass", "actual"=>"Pass", "result"=>true}, "Script 2"=>{"expected"=>"Pass", "actual"=>"Pass", "result"=>true}

I will have to parse the .log files which will contain multiple lines and get the above given lines alone.

The only thing common to be used to get this is the first text : "Result for scripts as follows" .

Any suggestions to solve this using Ruby or any powershell commandsRU

lundi 27 avril 2020

how to pass the return value of function with & operator in ruby?

I came across following code snippet in ruby, where the safe navigation operator is used to call a second method, in the example below, does the response we get from Excon.get call passed to the process_json automatically. in the function definition of process_json ,there is no parameter being passed. I am not sure how this might work.

class Client
   API_ENDPOINT = 'https://api.twitter.com'

   class << self
      def call()
       Excon.get(API_ENDPOINT)&.process_json
      end

      def process_json
         //process json response
      end
    end
end

confirmation token Automatically generated NIL

Hello guys, I have an issue with automatically generated token. In a model, i generate token automatically like this:

class User < ApplicationRecord
  before_create :generate_confirm_token

  def generate_confirm_token
    self.confirm_token = generate_token
  end

  def generate_token
    loop do
      token = SecureRandom.hex(10)
      break token unless User.where(confirm_token: token).exists?
    end
  end

That works fine for me, after creating of user, the token is generated. But the issue is in a Controller:

class Companies::StudentsController < ApplicationController


  def create
    @company = Company.find(params[:company_id])
    @student = @company.students.create(student_params)
     raise @student.inspect
    if @student.save
      StudentMailer.with(student: @student).welcome_email.deliver_now
      redirect_to company_students_path
    else
      render :new
    end
  end

Object student, contains confirm_token BUT in a params, the confirm token is empty!

enter image description here I need the token in params because in next step (mailer) i use Find_by(params[:confirm_token]) Here is how use a confirm_token in my view (i assume i need the confirm_token in params so i have to have it in a view also):

  <%= f.hidden_field :confirm_token %>

I dont know how to solve it, but I think i need a token value in a params - but how to put the value there? Thank you!

dimanche 26 avril 2020

How to write if statement in table

I'm trying to write an if statement in a table to get one image if an image doesn't exist in the database. Im able to retrieve both images separately but not with the if statement. What am I doing wrong in my code.

<h1>Won Auctions</h1>
<br>

<table class= "table table-hover" >
  <thead>
    <tr>
        <th>Name</th>
        <th>Price</th> 
        <th>End Date</th>
        <th>Seller</th>
        <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% won.each do |a| %>
      <tr>
        <td><%= 
        if a.image.exists? %>
          <%  image_tag(a.image, width:100) %>
        else
          <% image_tag("No_image.jpg", width:100) %>
          <% end %>
         %><td>
        <td><%= a.name %></td>
        <td><%= number_to_currency(a.highest_bid) %></td>
        <td><%= a.auction_end_time %></td>
        <td><%= a.seller.email %></td>

      </tr>
    <% end %>
  </tbody>
</table>

<br>

Why psql can not connect to server?

When I run the command Rails s and refresh http://localhost:3000/ . I get the following error :

Internal Server Error
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
WEBrick/1.6.0 (Ruby/2.7.1/2020-03-31) at localhost:3000

I have tried every possible solution given on StackOverflow. it isn't working for me .

I am using Rails on Bash in Ubuntu for Windows.Here are the versions : Rails 4.2.10 Ruby 2.7.1p83 railties-4.2.10