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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:41:57+00:00 2026-06-10T05:41:57+00:00

Here is the partial form causing the Template error in rspec controller test: <%=

  • 0

Here is the partial form causing the Template error in rspec controller test:

<%= f.label :expense_for, '栏目:'%>
<%= f.select :expense_for, @expense_for.map { |expense| [expense, expense] }, {:include_blank => true, :selected => @expense.expense_for } %>

We use render_views in expenses controller test. Since @expense_for is nil in create test, so .map causes error:

[31mActionView::Template::Error:←[0m
       ←[31mundefined method `map' for nil:NilClass

The rspec code which causes the error above is:

get 'create', :expense => e, :expense_for => ['a','b']

In expenses controller, @expense_for is defined in new as:

  def new
    if has_create_right?
      @expense = Expense.new(params[:expense], :as => :role_new)
      if @expense.expense_type == 'production'
        @expense_for = return_expense_for_production
      elsif @expense.expense_type == 'overhead'
        @expense_for = return_expense_for_overhead
      else
        @expense_for = []
      end
    end

The @expense_for is filled up with ajax call.

How can I pass a value to @expense_for in partial form for rspec test? 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-10T05:41:59+00:00Added an answer on June 10, 2026 at 5:41 am

    if @expense_for is nil in your test, then has_create_right? is false, so @expense_for is never being set. Try setting @expense_for to [] at the beginning of the action, instead of in the else clause.

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

Sidebar

Related Questions

Here's the situation: I've got two partial views. One has a form. What needs
I get an error while adding a partial form to my current form (kind
I've added a select box to a form partial, but unsure about how to
my question is that I have made multimap.Here is the partial code. if(binary_search(final.begin() ,
Here is my code: public partial class Image : System.Web.UI.Page { protected void Page_Load(object
Here is my code: partial void OnisApprovedChanging(bool value) { this.dateApproved = DateTime.Now; } 'dateApproved'
Here's what I want the resulting class declaration to look like: public sealed partial
public partial class Form1 : Form { string[] id; private void button_Click(object sender, EventArgs
I'm creating a multi-part form in the style that Ryan Bates describes here: http://railscasts.com/episodes/217-multistep-forms
Here is code on view in FeesController show action template: <div id=payers_controls> <%= link_to_remote('New

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.