Note that there are some explanatory texts on larger screens.

plurals
  1. POHow reliable is the action_name method in rails?
    primarykey
    data
    text
    <p>How can I ensure that the controller.action_name returns correct information? I rely on that to generate user-friendly messages in the menu bar. Consider the following scenario.</p> <p>The action_name method works great when I use:</p> <pre><code>redirect_to edit_profile_path # I get action_name as "edit" in my ApplicationController </code></pre> <p>But it does not yield the information I need when I use the following:</p> <pre><code>render :action =&gt; "edit" # The action_name shows as "get" instead of "edit" </code></pre> <p>Is there a way I can use render action and still get the correct action_name?</p> <p>Thanks, Tabrez</p> <p>---- code snippets in response to Mischa's comment ----</p> <p>This is what I have in the controller: </p> <pre><code>def update if @profile.update_attributes(params[:profile]) format.html { flash.now[:notice] = 'Profile was successfully updated.' render :action =&gt; "edit" } end </code></pre> <p>I am not redirecting because I still want the user to stay in the edit mode. </p> <p>In my application helper I have code to the following effect:</p> <pre><code>if(action_name == "edit" &amp;&amp; (can? :read, l_disp_object) ) then path_links_subheader.concat(link_to 'Show Saved Version', :controller =&gt; controller.controller_path, :action =&gt; :show) end </code></pre> <p>Basically, if the user is in edit mode, I want the "Show Saved Version" link on the menu. But, when I use the "render :action" syntax, the action changes to "get", which makes sense based on what Mischa mentioned (action being a misnomer there..). So, is there a way I can accomplish this without issuing a redirect? The only reason I am not already using redirect is that the logic for retaining the current tab for the user works with render action. I might have to rewrite it if the only possible way to accomplish this is via redirects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload