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

  • Home
  • SEARCH
  • 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 7834613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:15:34+00:00 2026-06-02T13:15:34+00:00

I am working on a app where you can add task etc. I know

  • 0

I am working on a app where you can add task etc. I know this is kind of weird but I just like to see how others would implement this. How would you change the following code into a helper method and use it?

The original code

<h2>My Tasks</h2>
<% task = @work.tasks %>
<% if task.empty? %>
  <%= link_to 'Create a new task', new_task_path %>
<% else %>
  <%= render :partial => 'notes/note', :locals => {:note => @note} %>
<% end %>

My way of doing a helper method

def task_check
  task = @work.tasks 
  if task.empty? 
    link_to 'Create a new task', new_task_path
  else 
    render :partial => 'notes/note', :locals => {:note => @note} 
  end 
end

In my view

<%= @work.task_check %>
  • 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-02T13:15:35+00:00Added an answer on June 2, 2026 at 1:15 pm

    Personally, I wouldn’t extract this out at all, this is view logic and it belongs in the views. It definitely doesn’t belong in a model, but it could arguably be extracted into a helper. I’d change it slightly:

    <h2>My Tasks</h2>
    <% if @work.tasks.blank? %>
      <%= link_to 'Create a new task', new_task_path %>
    <% else %>
      <%= render :partial => 'notes/note', :locals => {:note => @note} %>
    <% end %>
    

    Calling blank? instead of empty? will work even if @work.tasks is nil

    .

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

Sidebar

Related Questions

i have this issue working but i would like to know if there is
i am working on app which deals with proximity alerts. I can add proximity
I have createn an app, this app can be found here Everything is working
Even using the default test code on my app I can't get this working.
the working scenario on a web bases app like a forum, the users can
I tried working with ProtoRPC and I really like how easily I can add
This was working just the other day, but I just updated my code to
I'm working on a task manager app and want to add a recurring/repeating tasks
i am working on one music app where we can import music from iPod
I've got style resources in WPF working so that in my App.xaml I can

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.