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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:44:46+00:00 2026-06-02T22:44:46+00:00

I am just starting to pick up Ruby on Rails. I rather like it,

  • 0

I am just starting to pick up Ruby on Rails. I rather like it, but I ran into a roadblock. I know of two ways to solve a problem but I am curious as to what the “Rails Way” to do this is.

The Setup

I have an index page that lists project descriptions. When a user clicks on a project it brings them to the show function of the projects controller. Projects in the list are loaded from a MySQL database.

What I Want To Do

I want to be able to load project specific information on each “Project Page.” This information consists of documentation, code examples, etc. Each page will have the same general template.

Way 1

Store the HTML and text in the MySQL database in a “Sections” table and load all the sections related to that project. Display each section going down the page.

Way 2 (The way I would rather do it)

Have a separate view for each project with the full documentation. Load a specific view based on the project that is loaded in the show function

Comments

Is there some third way in Rails that I am not used to thinking of since I come from using CodeIgniter?

I am completely up for adapting to what the “Rails Way” is, but I am just not sure what the proper convention for this kind of thing is.

Or is this problem a case of, it does not matter how you do it at all?

Thanks in advance.

  • 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-02T22:44:47+00:00Added an answer on June 2, 2026 at 10:44 pm

    There are many ways to do this, one of the easiest ways is to override default template.(render :action doesn’t run any code in the target action only template)
    This is Way2 in your question. Example:

    def show
      @project = Project.find(params[:id])
      if @project.has_template?
        render :action => "show_#{@project.template_name}" and return
      end
      render :action => "show"
    end 
    

    In this example directory app/views/projects should have templates for each project
    with names like “show.html.erb” for default one and “show_myspecialproject.html.erb” for project with template_name “myspecialproject” , etc….

    Template_name is a method that tell you if project has such or should use default, you can put any logic in this method, it can be additional column id table or just template_name can be equal to project name, or it can just check if file exist in current directory.

    You can also use partial templates if you want to use show.html.erb because you have code duplications and keep your templates DRY.
    http://rails.rubyonrails.org/classes/ActionView/Partials.html
    This way

    controller action is default

    def show
        @project = Project.find(params[:id])      
    end 
    
    
    
    in show.html.erb
    <h1><%= @project.name %></h1>
    <%= render @project.tamplate_name %>
    

    In this example all partial templates should start with “_” ,
    Ex. : “_myspecialproject.html.erb”

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

Sidebar

Related Questions

I'm just starting to learn ASP.NET MVC and I'd like to know how I
I'm just starting to try to pick up the J language, and am confused
Just starting out, this should be a simple one but I haven't been able
Just starting to use Cruise Control, but can't seem to find anything on this
Just starting to look into WCF and came across the WSDualHttpBinding binding. I have
Just starting with php and sorry if this is a newbie question but i'm
Just starting to use CodeIgniter, and I'd like to import some of my old
I'm just starting to pick up ASP.Net MVC and find myself writing a lot
I am just starting to pick up NAnt as a replacement for MSBuild in
Just starting to look into using LinqDataSource for a GridView and I’m looking for

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.