How can I check this ?

9 views
Skip to first unread message

Roelof Wobben

unread,
Jun 30, 2014, 11:19:12 AM6/30/14
to rubyonra...@googlegroups.com
Hello,

Suppose I have this model :

class Member < ActiveRecord::Base
end

Now I have this controller :

class MemberController < ApplicationController
  def new
     @member = member
  end
end

and this form :

<h1>Add a new member</h1>
<%= form_for @member do |form| %>
 
  <p>
    <%= form.label :name, "Name: " %>
    <%= form.text_field :name %>
  </p>
 
  <p class='buttons'>
    <%= form.submit "Shorten my URL" %>
  </p>
 
<% end %>


Now I have filled in the form the name "roelof"

How can I later check if there is a member with the name "roelof"
or can I do @member.name = "roelof"

Roelof


Colin Law

unread,
Jun 30, 2014, 11:49:03 AM6/30/14
to rubyonra...@googlegroups.com
To test if a particular member (in @member) has that name then you
would have to use
if @member.name == "reolof"

But if you mean after you have saved it to the database you want to
know if there is a member with that name then you can see if
Member.where(name: 'Reolof'')
returns any records.

Or is that not what you mean?

Colin

Roelof Wobben

unread,
Jun 30, 2014, 11:59:40 AM6/30/14
to rubyonra...@googlegroups.com
Thanks,

The last one is what I needed.
Now I have to figure out how I can use this in a cucumber scenario.

Roelof


Op maandag 30 juni 2014 17:49:03 UTC+2 schreef Colin Law:
Reply all
Reply to author
Forward
0 new messages