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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:14:16+00:00 2026-05-25T15:14:16+00:00

Use method in helper to hide or show a link accordingly. The method new_cate?

  • 0

Use method in helper to hide or show a link accordingly. The method new_cate? works as designed. However the method link_to_edit? causes the following error:

undefined local variable or method `cate' for #<#<Class:0x4ed6a10>:0x4ed2d38>

Extracted source (around line #23):

20:   <tr>
21:     <td><%= cate.name %></td>
22:     <td><%= cate.description %></td>
23:     <td><%= link_to_edit? %>></td>
24: 
25:   </tr>
26: <% end %>

Here is the code:

in index.html.erb

<body>

<h2>Category</h2>
<table>
  <tr>
    <th>Category</th>
    <th>Description</th>

  </tr>

<% @categories.each do |cate| %>
  <tr>
    <td><%= cate.name %></td>
    <td><%= cate.description %></td>
    <td><%= link_to_edit? %>></td>

  </tr>
<% end %>
</table>

  <%= new_cate? %>

</body>

in categories_helper.rb

  def new_cate?
    if session[:eng_dh] 
      return link_to 'New Category', new_category_path
    end
  end

  def link_to_edit?
    if session[:eng_dh]
      return link_to 'Edit', edit_category_path(cate)
    end
  end

The code following “return” seems weird. new_cate? works as designed. But link_to_edit? does not.

Any thoughts? 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-05-25T15:14:17+00:00Added an answer on May 25, 2026 at 3:14 pm

    You are referring to a method scope variable (which is not yet declared in that scope).

    I guess what you want is

    #in controller
    def link_to_edit cate
    if session[:eng_dh]
      return link_to 'Edit', edit_category_path(cate)
    end
    

    end

    #in view
    <% @categories.each do |cate| %>
      <tr>
        <td><%= cate.name %></td>
        <td><%= cate.description %></td>
        <td><%= link_to_edit cate %>></td>
    
      </tr>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can use the ActionView helper strip_tags method in my views to
I wish to use the method with the following signature: exec(String command, String[] envp,
actually i use this method to show similar words for a search request.. $query
Is there any way to use a Rails helper method, more specifically, a path
For setting that I use Html helper method which is not the best imo,
I want to use a method i have in my helper inside my controller.
I want to use this helper method on controller. Any way to achieve this?
It's a little unclear for me on when to use a custom helper method
I use special method to create sandobx: internal static class Helper { public static
I've found a helper method that I would like to use to resize embedded

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.