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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.
On Friday, November 29, 2013 10:18:26 PM UTC, Ankur wrote:> > > 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? > > > So what does happen when you click on the form''s button ? Did you look atyour application logs / server output? At first glance you''re posting to the wrong url - to create a new task you post to tasks_path where you have forced the url to task_path (which would be appropriate for updating an existing task). Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/46cf8fba-f24b-4eec-896c-b87e5ee4bca8%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Hi Frederick,
If I change the path to tasks_path, I get the following error while
navigating on to the page which has this form. If I keep task_path,
navigation works fine.
undefined local variable or method `tasks_path'' for
#<#<Class:0xa3de690>:0xb550f644>
I don''t see any error in development.log when I click on the Add
button.
the page re-loads as expected because of "task_path" url but data
doesn''t
persist.
*Trace:*
Started POST "/task" for 127.0.0.1 at 2013-11-30 15:11:15 +0530
Processing by HomeLoginController#task as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"wXpiPiPabBjOBN1iqF/Hj4z81y3RCcSj/gRSpWFuIC0=",
"task"=>{"name"=>"eeff"},
"commit"=>"Add"}
^[[1m^[[36mUser Load (0.2ms)^[[0m ^[[1mSELECT "users".* FROM
"users"
WHERE "users"."id" = 1 LIMIT 1^[[0m
^[[1m^[[35mTask Load (0.2ms)^[[0m SELECT "tasks".* FROM
"tasks"
Rendered home_login/_job_form.html.erb (1.2ms)
Rendered home_login/task.html.erb within layouts/application (67.2ms)
Completed 200 OK in 97.6ms (Views: 93.5ms | ActiveRecord: 0.4ms)
Also, I missed adding create action in controller earlier, have added it
now:
* def create*
* Task.create params[:task]*
* redirect_to :back*
* end*
Thanks.
--
Regards,
Ankur
On Sat, Nov 30, 2013 at 3:09 PM, Frederick Cheung <
frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
> On Friday, November 29, 2013 10:18:26 PM UTC, Ankur wrote:
>>
>>
>> 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?
>>
>>
>> So what does happen when you click on the form''s button ? Did
you look at
> your application logs / server output? At first glance you''re
posting to
> the wrong url - to create a new task you post to tasks_path where you have
> forced the url to task_path (which would be appropriate for updating an
> existing task).
>
> Fred
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/rubyonrails-talk/46cf8fba-f24b-4eec-896c-b87e5ee4bca8%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/CALSL1eNC5VxTzMzRH8B7yM98LaMWekRaSJmK36g_5uq0e4-NzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
On 29 November 2013 22:18, Ankur Kumar <specialankur-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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.Can I suggest that you work right through a good tutorial such as railstutorial.org (which is free to use online). That will show you the basics of rails so that you will be able to answer simple questions yourself. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu_UQSRoeVopJA%3DF8m%2B%3DJDc8O2RRbGY93DS9G43AucqEw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Saturday, November 30, 2013 10:11:12 AM UTC, Ankur wrote:> > > > Also, I missed adding create action in controller earlier, have added it > now: > > * def create* > * Task.create params[:task]* > * redirect_to :back* > * end* > >Did you add a route for your create action ? That would also explain why tasks_path raises an exception (I was assuming you had resources :tasks in your routes). As Colin says, this sort of stuff is covered by most tutorials. This will also get you on the path of using standard naming conventions, which makes things a lot easier. Fred Thanks.> > -- > Regards, > Ankur > > > > On Sat, Nov 30, 2013 at 3:09 PM, Frederick Cheung <frederic...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> > > wrote: > >> >> >> On Friday, November 29, 2013 10:18:26 PM UTC, Ankur wrote: >>> >>> >>> 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? >>> >>> >>> So what does happen when you click on the form''s button ? Did you look >> at your application logs / server output? At first glance you''re posting to >> the wrong url - to create a new task you post to tasks_path where you have >> forced the url to task_path (which would be appropriate for updating an >> existing task). >> >> Fred >> >> -- >> 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-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/46cf8fba-f24b-4eec-896c-b87e5ee4bca8%40googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b94dbc61-bd14-4103-a268-a789da32b035%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.