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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:08:10+00:00 2026-06-01T17:08:10+00:00

In my application_controller I’ve added: def instantiate_controller_and_action_names @current_action = action_name @current_controller = controller_name end

  • 0

In my application_controller I’ve added:

def instantiate_controller_and_action_names
          @current_action = action_name
          @current_controller = controller_name
      end

so that I show/hide certain fields in my views depending on the current action. For example, when adding a new user, I want the ability to show a password field to be filled out, but when editing a user, I don’t want the password field to display.

The problem I’m having is that @current_action only returns a value of ‘new’ when creating a new record, but isn’t returning a value when I’m editing a record (e.x.- http://localhost:3000/users/6/edit), or if I use the inverse and check if the @current_action != ‘new’…in both cases my field is still being displayed.

<%if @current_action != 'new'%>
   <tr><td>AAAAAAA</td></tr>
   <%else%>   
   <tr>
    <th class="">Password</th> 
    <th class="">Password Confirmation</th> 
  </tr>
  <tr>
    <td><%= f.password_field :password %></td>
    <td><%= f.password_field :password_confirmation %></td> 
  </tr>
<%end%>

What is happening that ‘edit’ isn’t being returned and/or is there a better/best practice way to accomplish this? Thanks!

  • 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-01T17:08:10+00:00Added an answer on June 1, 2026 at 5:08 pm

    Rather than use the controller action, why do you not test your object? You can see if your object is a new record or not with this method

    <% if f.object.new_record? %>
      Your code for new object
    <% else %>
    You code to edit object
      <%end%>
    

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

Sidebar

Related Questions

I have the following application_controller method: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) end Should I
I understand that application_controller.rb is the place to put all the methods, etc that
I understand that the application_controller will produce variable values for an entire application but
In my application_controller.rb I have: class ApplicationController < ActionController::Base helper :all def test1? true
In application_controller I have the following method: def authorized_for_roles(*roles) roles.each{|role_name| return true if current_user.has_role?(role_name)}
In my application-controller.rb I did: def show_footer? @show_footer = true end Then in my
Can I create a default property on the base Application_Controller that can be accessed
I've a current_user method to handle authentication. application_controller.rb protect_from_forgery helper_method :current_user def current_user @current_user
I have got two methods in application_controller.rb def force_ssl if !request.ssl? redirect_to :protocol =>
I have the following in my application_controller.rb def layout unless request.subdomain.empty? && current_user.nil? self.class.layout

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.