Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6104753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:52:40+00:00 2026-05-23T13:52:40+00:00

I have this code-snippet in html erb. For some objects the cover_image_url is empty,

  • 0

I have this code-snippet in html erb.

For some objects the cover_image_url is empty, how do i modify this code block to use a default value ,when that property is null or empty?

<%@books.each do |book|%>
        $('#bookContainer').append('<div class="conn"><p><img class="floatright" src="<%= h book.cover_image_url%>"><h3><%= h book.title%></h3><h3><%= h book.author%></h3></p></div>');
    <% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:52:40+00:00Added an answer on May 23, 2026 at 1:52 pm

    You could define a cover_image_url method on your book model that will return a default value if there is nothing set in the database (I am assuming that cover_image_url is a column in the book table). Something like this:

    class Book < ActiveRecord::Base
      def cover_image_url
        read_attribute(:cover_image_url).presence || "/my_default_link"
      end
    end
    

    This will return "/my_default_link" if the attribute is not set, or the value of the attribute if it is set. See section 5.3 on The Rails 3 Way for more info on this stuff. Defining a default value for a model in the model layer may be a little cleaner than doing it in the view layer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have this HTML code snippet: <div id=container> <div id=textContent>Text Content Te</div>
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
Given this code snippet, I know that if the user selects 25c the value
can this code snippet be modified to reveal html coding? <?php $_option = $this->getOption()
I have this simple snippet with an ActionLink that is supposed to display some
I have this chunk on jQuery and currently its living in my index.html.erb and
I have some JavaScript code that dynamically injects an iframe in a given HTML
Please consider this code snippet: var ul = $(.list_b).find(li).remove().end(); $.each(Sites, function (index, value) {
In my views.py, i have a snippit of code like this: def clean_post_data(form): for
I have this code in jQuery, that I want to reimplement with the prototype

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.