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 7985841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:40:26+00:00 2026-06-04T11:40:26+00:00

Here is the trick. I have a model called Pages with a field called

  • 0

Here is the trick. I have a model called Pages with a field called “page_type” wich can be one of, lets say, 3 variants: “html”, “image”, “vcard”, and a field called “content”.
So now I need the app to respond with different mimetypes depending on what type of a page is requested.

If the page_type is set to “html” – render the content as html using the appropriate view and html_safe, that’s easy.

If the page_type is set to “image” – get the image, using the path, stored in the content and send it back to the user as if he requested an image.

Same for “vcard”.

How can I do that?

  • 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-06-04T11:40:27+00:00Added an answer on June 4, 2026 at 11:40 am

    If you’re generating the URLs to access your resources (Page) in your app, you can specify the resource location RESTfully, such as /pages/2.jpg, /pages/3.vcard, /pages/4 (default is html) using the built-in Rails view helpers such as page_url(@page, :format => ‘jpg’). Then it’s simply a matter of using repond_to in Rails to deliver the resource:

    respond_to do |format|
      format.html { # default rendering in show.erb.html }
      format.jpg { # perhaps send_file or send_data call }
      format.vcard { # send attachment }
    end
    

    Check out the Rails Routing Guides for more info. You’ll need to configure Rails to handle requests for .vcard. See this gist.

    If you don’t control link generation (external references to your resources) and expect to get requests like /pages/2 (which is a jpeg), then you’ll have to fall back to using your page_type column to conditionally render with send_file, send_data, or other Rails rendering methods. You might consider re-using the logic (methods) you create for each block in respond_to above, so that your controller has ‘respond_to_html’, ‘respond_to_jpg’, ‘respond_to_vcard’ methods.

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

Sidebar

Related Questions

I have some complex types here so I decided to use nifty trick to
I have a model called a voip_phone that has a an attribute schedule which
I have a model with some inheritance worked into it, but here's the thing,
Here is my model_users class (the model it extends from doesn't have anything yet
I have a model called Profile which is belong_to User, so there is 'user_id'
Let's say I have some contrived models: class Author(Model): name = CharField() class Book(Model):
In my project, I have two Core Data entities. One is the grouping (can
here's a tricky question... I have default styled input fields (no css added, just
Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on
I have what I think is a tricky question, but hopefully someone on here

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.