Ruby on Rails Friday, November 29, 2013


Hi,

I created a simple form using form_for and partials. When I enter a value in text field and click on add button, the data doesn't get uploaded in database table. 

view/task.html.erb
<%= render :partial => "job_form" %>

<% for job in @jobs %> 
<%= job.name %>
<% end %>

view/_job_form.html.erb
<%= form_for(@job, :url => task_path) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit "Add" %>
<% end %>

/view/home_login_controller.rb
def task
@job = Task.new
@jobs = Task.all
end

db/<migration stamp>_create_tasks.rb
def change
    create_table :tasks do |t|
   t.string :name
          t.timestamps
    end
 end

db/schema.rb
 create_table "tasks", :force => true do |t|
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.string   "name"
  end

app/models/task.rb
class Task < ActiveRecord::Base
  # attr_accessible :title, :body
end

I have done db migration and db schema exists for table but "select * from tasks" doesn't return any rows and therefore UI doesn't show any form data. Can someone please help me debug this issue? 

Thanks. 
--
Regards,
Ankur 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALSL1eOOmhPeuvcKcfKe%2BwaUiV66oXw9fJ-VcUC_ityJEKG%3DQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment