Folks im new to rails and was wondering how i would access these
elements from my view


in my controller i have
@data = Editpatient.find(:all, :conditions => ["patient_id = ?",
params[:patients]] )

and in the view i have <%= @data %>

this displays all the data but i only want one field. This is what is
displayed.

[#<Editpatient id: 27, patient_id: 14, provider_id: 11, weight_gained:
123, weight_lost: nil, created_at: "2011-11-26 21:07:13", updated_at:
"2011-11-26 21:07:13", patient_name: nil, provider_name: nil>]

the only field i want is patient_id

ive tried this in the view @data[:patient_id] and i get
can't convert Symbol into Integer

any help is appreciated thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Hassan Schroeder at Nov 26, 2011 at 11:42 pm

    On Sat, Nov 26, 2011 at 3:00 PM, brent brent wrote:

    @data = Editpatient.find(:all, :conditions => ["patient_id = ?",
    params[:patients]] )
    erm, well. If you expect to get back one record for a given patient_id
    it could be more readably expressed as:

    @editpatient = Editpatient.find_by_patient_id(params[:patient_id])

    (assuming you fix your form to pass 'patient_id').
    and in the view i have <%= @data %>
    Which is opaquely named, and hides the fact that you're fetching
    an array.
    this displays all the data but i only want one field. This is what is
    displayed.
    @data.first.patient_id

    would do it, but I'd strongly recommend cleaning up the code to make
    your intent more apparent, and only fetch one record, e.g.

    @editpatient.patient_id

    HTH,
    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Brent brent at Nov 26, 2011 at 11:56 pm

    brent brent wrote in post #1033872:
    Folks im new to rails and was wondering how i would access these
    elements from my view


    in my controller i have
    @data = Editpatient.find(:all, :conditions => ["patient_id = ?",
    params[:patients]] )

    and in the view i have <%= @data %>

    this displays all the data but i only want one field. This is what is
    displayed.

    [#<Editpatient id: 27, patient_id: 14, provider_id: 11, weight_gained:
    123, weight_lost: nil, created_at: "2011-11-26 21:07:13", updated_at:
    "2011-11-26 21:07:13", patient_name: nil, provider_name: nil>]

    the only field i want is patient_id

    ive tried this in the view @data[:patient_id] and i get
    can't convert Symbol into Integer

    any help is appreciated thanks
    Thanks for the help Hassan
    This is just a test app that im using to get the hang of ruby and rails.
    Your method worked perfectly.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 26, '11 at 11:01p
activeNov 26, '11 at 11:56p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Brent brent: 2 posts Hassan Schroeder: 1 post

People

Translate

site design / logo © 2021 Grokbase