New to ruby (easy question i think)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JackInDaBox
    New Member
    • May 2007
    • 6

    #1

    New to ruby (easy question i think)

    Hello I am new at ruby on rails and have what i hope is a simple question. Say I have a DB with animal names and an id. I am using active scaffold. once I click on the edit to edit any animal name how can i then access that that name in the view? I want to be able to output it in the textbox name: as well as just display it below the textbox that active scaffold creates.

    Thanks for the help
  • asrinivas1234
    New Member
    • Dec 2007
    • 4

    #2
    Originally posted by JackInDaBox
    Hello I am new at ruby on rails and have what i hope is a simple question. Say I have a DB with animal names and an id. I am using active scaffold. once I click on the edit to edit any animal name how can i then access that that name in the view? I want to be able to output it in the textbox name: as well as just display it below the textbox that active scaffold creates.

    Thanks for the help
    ............... ....
    u have to pass the id for the particular selected animal..

    how can u do it?

    in first page, u r displaying the animals right?
    how do u display animals?
    u r fetching from database in controller and assigning that object and inside the .rhtml page, u r catching that object and iterating that object and displaying the animals.
    Ex:
    in controller-->
    @animals = Animal.find :all

    inside view,
    <%for animal in @animals%>
    <% form_tag :action => 'edit', :id => animal.id do %>


    <%end%>
    <%= submit_tag 'edit' %>

    have u seen the form statement,
    :id => animal.id.

    then, inside ur controllers edit method,
    def edit
    @animal = Animal.find(par ams[:id])
    end

    then,
    inside ur 2nd rhtml page,
    u can use @animal and print the corresponding data...

    if u have doubt,
    u can mail me, --> avasarala.asrin ivas@gmail.com

    Comment

    Working...