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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:58:19+00:00 2026-05-23T17:58:19+00:00

I’m playing around with RoR for the first time and hit a weird error.

  • 0

I’m playing around with RoR for the first time and hit a weird error. I have the following test code for my navigation links:

describe "when logged in" do 
  before(:each) do
    @user = Factory(:user)
    visit login_path

    #the line below is the weird one
    fill_in "session[user_name]", :with => @user.user_name

    fill_in :password, :with => @user.password
    click_button
  end

  it "should have navigation links" do
    response.should have_selector("nav")
  end

  it "should have link to log out" do
    response.should have_selector("a", :href => logout_path, :content => "Log out")      
  end  
end

the code above works just fine, but if I would change the line

fill_in "session[user_name]", :with => @user.user_name

to

fill_in :user_name, :with => @user.user_name

it won’t work and I can’t figure out why. The error I get is

Failure/Error: fill_in :user_name, :with => @user.user_name
   Webrat::NotFoundError:
   Could not find field: :user_name

The relevant generated html is:

<label for="session_user_name">User name</label><br/>
<input id="session_user_name" name="session[user_name]" size="30" type="text" />
<label for="session_password">Password</label><br/>
<input id="session_password" name="session[password]" size="30" type="password" />

If you look at the code you see I do exactly that for the password, and that works just fine. I would like to use the syntax which is causing the error so am I doing something wrong?

  • 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-23T17:58:20+00:00Added an answer on May 23, 2026 at 5:58 pm

    Try this:

    fill_in "user name", :with => @user.user_name
    

    I think webrat is being nice, and its able to find your label ‘Password’ because it is case insensitive and its turning :password into ‘Password’.

    You could also use the HTML id attribute, i.e.

    fill_in :session_user_name, :with => @user.user_name
    

    One gotcha here is if you are thinking of switching to use Capybara rather than Webrat: Capybara is case-sensitive, so it would fail on fill_in "user name".

    I’m not sure what the best practice is here, but I have switched to using the HTML id and name attributes rather than the label text in my own code. The reason for this is that it is less brittle because people change the customer-facing text on the site more than they change the semantic elements and names.

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.