I need to add the following features to my existing code (posted below) in Rails using Jquery, JSON, Ruby and HTML. I have a lot of ideas and researched a bit but Itd be great if someone can help me with integrating them:

I need to add a feature to sign a url associated with each file in my table.Where the url is say a 'string1' + the prefix from <%= hidden_field_tag :prefix, @prefix %> I was thinking of using the 'aws_cf_signer' gem in rails and code such as : -

signer = AwsCfSigner.new('./private-key-file.pem')
url = signer.sign(url)

I need to replace/modify the form within the second 'td' element in the view code in RAILS below to allow the user options to create shortlinks with expiration dates for each url: (can be multiple for each file)

For this I am using the 'url_shortener' gem and code:

  authorize = UrlShortener::Authorize.new 'xxxxxxx', 'yyyyyyy' 

  client = UrlShortener::Client.new(authorize) 
My Approach:

for creating the expiration dates --- I would have the user input a date via a datepicker (using the Jquery-ui gem for rails).

JSON : for Serialization and Deserialization of Ruby objects --I would use an array of hashes named say 'links' and then use

JSON.generate(links) for serialization and 
 JSON.parse() for deserialization. 

I would loop through the array (get the original object).

MY CODE SO FAR:

I am using JQuery to display a corresponding hidden 'td' element (hidden using css ---> display:none) when a specific button is clicked by a user in a table.

Code for View:

<h2>Files</h2>
<table class="table">
<tr>
<th>Filename</th>
<th>Description</th>
<th>Download Link</th>
</tr>
<% @files.each do |file| %>
<% filename = file.split('/').last %>
<% object = @bucket.objects[file] %>

<tr>         
<td><%= filename %></td>  

<td>
<div class="file_description"><%= object.metadata['description']%>    
<button id     ="file3" type="button"  class= "btn btn-default   
  edit_description"   onclick="Window(this)">Edit</button>                      
 </div>
 <div id = file2 class="file_description_update" >
  <%= form_tag({:action => 'update_file_info'}, multipart: true) do %> 
    Update File Description: <%= text_area_tag :description %>
    <%= hidden_field_tag :s3_path, file %>  
    <%= hidden_field_tag :prefix, @prefix %>
    <%= submit_tag 'Submit' %> </td> <br />
  <% end %>
  </div>

  </td> 

  <td><%= link_to "Download", download_url_for(file) %></td>

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

Current JQuery code :

$(document).ready(function(){ 
$( "button.edit_description" ).on( "click", function( event ) { 
$(this).closest('td').find( "div.file_description_update" ).show(); 
}); 
 });

Id really appreciate if someone can help me with most parts of the above features!Can someone please guide me with code for this? Thanks

Dani AI

Generated

A practical way to approach this is to split it into three focused pieces: a short-link data model and API, a server-side URL signer, and a small front-end flow (datepicker + AJAX). is right that it’s several features — implement them one at a time and you’ll have a robust result for to integrate.

Keep shortlinks as real records (one row per shortlink) instead of stuffing arrays into object metadata. Minimal model ideas: token (unique), s3_path (original object key), expires_at (datetime) and optional metadata. Example controller-create flow (Rails): validate/parse the date from the datepicker, generate a URL-safe token, persist the row, then return the new short URL as JSON.

# config/routes.rb
get '/s/:token', to: 'short_links#show', as: :short_link

# app/controllers/short_links_controller.rb (create)
def create
  expires = Time.zone.parse(params[:expires]) rescue nil
  token = SecureRandom.urlsafe_base64(6)
  link = ShortLink.create!(token: token, s3_path: params[:s3_path], expires_at: expires)
  render json: { short_url: short_link_url(link.token) }
end

For signing, a simple and safe pattern is HMAC-SHA256 with a server secret stored in ENV. Sign the original URL plus an expiry timestamp and append both to the download link. Verify the signature and expiry on access. Example sign/verify helpers:

def sign_url(url, secret, expires_in: 3600)
  expires = (Time.now.to_i + expires_in).to_s
  sig = Base64.urlsafe_encode64(OpenSSL::HMAC.digest('sha256', secret, "#{url}|#{expires}"))
  "#{url}?expires=#{expires}&sig=#{sig}"
end

Notes and troubleshooting: never commit secrets or private keys; use ENV or a secrets manager. Enforce expiry on the show action and use a timing-safe comparison for signatures. Prefer server-side storage for shortlinks so you can index, expire, and audit them easily. For the UI, use event delegation (no inline onclick), a datepicker for expiry, and an AJAX POST to the create action; display the returned short_url in the same table row.

Member Avatar for Member #949455

Id really appreciate if someone can help me with most parts of the above features!Can someone please guide me with code for this?

A lot of Daniweb members will have a hard time assisting with this because it's alot of work. You can't expect someone to guide you with this. Either you solve on your own or pay someone to do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.