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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:40:00+00:00 2026-05-14T18:40:00+00:00

For example, I might have an partial something like: <div> <%= f.label :some_field %><br/>

  • 0

For example, I might have an partial something like:

<div>
  <%= f.label :some_field %><br/>
  <%= f.text_field :some_field %>
</div>

which works for edit AND new actions. I also will have one like:

<div>
  <%=h some_field %>
</div>

for the show action. So you would think that all your partials go under one directory like shared or something. The problem that I see with this is that both of these would cause a conflict since they are essentially the same partial but for different actions so what I do is:

<!-- for edit and new actions -->
<%= render "shared_edit/some_partial" ... %>

<!-- for show action -->
<%= render "shared_show/some_partial" ... %>

How do you handle this? Is a good idea or even possible to maybe combine all of these actions into one partial and render different parts by determining what the current action is?

  • 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-14T18:40:00+00:00Added an answer on May 14, 2026 at 6:40 pm

    When I use shared directory, then inside I put model name and my partials have names like this:

    shared/person/_show.html.erb
    shared/person/_form.html.erb
    

    If you want to have one line to render form or show partial, then you can add helper:

    def render_form_or_show(model)
      if edit? || new? 
        return render :partial => "shared/#{model}/form"
      elsif show?
        return render :partial => "shared/#{model}/show"
      end
      return ""
    end
    

    If you fallow some rules, like putting your partials in shared directory and then in model directory, and then always have _form for edit and new, and _show for show action, then it will work ;). Of course you need to define edit? etc. methods:

    # Application controller
    def edit?
      params[:action] == 'edit'
    end
    

    Or maybe there is better way to get action name :).

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

Sidebar

Related Questions

I have a fairly simple ajax action link. The purpose of the action link
If you don't want any context or an example of why I need this,
Hopefully this example will illustrate my point better than simply trying to explain it:
I have a complex RIA client that communicates with a WCF SOAP web service,
In an ASP.NET MVC application implementing the repository pattern I am curious if it
I've just found out about Stack Overflow and I'm just checking if there are
I need to write some code that deals with generating and manipulating multivariable polynomials.
Are there any services available that allow me to manipulate maps in an offline
I've got a fancy-schmancy worksheet style view in a Rails app that is taking

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.