comopasta Gr
2010-Nov-17 15:29 UTC
Very confused - scaffold action does - sends NULL to db
Hi, I''m a bit confused with this. If you follow the steps below in Rails 3: 1- rails new act -d mysql 2- rails g scaffold action name:string 3- rake db:create 4- rake db:migrate 5- rails server when I add a record to that app I get: INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'') Note that NULL for the name value. I use as valid string but there is goes as NULL. Do another scaffold named act and everything goes fine with no changes. I could imagine that action is a reserved word but shouldn''t it complain about it? Any hints? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luciano Sousa
2010-Nov-17 15:34 UTC
Re: Very confused - scaffold action does - sends NULL to db
try added mannually using rails console $ Action.create(:name => "name example") and, post result. att: Luciano Sousa http://www.lucianosousa.net <http://www.lucianosousa.net>http://twitter.com/lucianosousa *Ruby on Rails Developer *Linux User #456387 *Contato: (21) 8418-5945 2010/11/17 comopasta Gr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> Hi, I''m a bit confused with this. > If you follow the steps below in Rails 3: > > 1- rails new act -d mysql > 2- rails g scaffold action name:string > 3- rake db:create > 4- rake db:migrate > 5- rails server > > when I add a record to that app I get: > > INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES > (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'') > > Note that NULL for the name value. I use as valid string but there is > goes as NULL. > > Do another scaffold named act and everything goes fine with no changes. > I could imagine that action is a reserved word but shouldn''t it complain > about it? > > Any hints? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-17 15:36 UTC
Re: Very confused - scaffold action does - sends NULL to db
comopasta Gr wrote in post #962162:> Hi, I''m a bit confused with this. > If you follow the steps below in Rails 3: > > 1- rails new act -d mysql > 2- cd act > 3- rails g scaffold action name:string > 4- rake db:create > 5- rake db:migrate > 6- rails server > > when I add a record to that app I get: > > INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES > (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'')What params are showing in your log? What''s the controller code that creates the record? You''ve provided us with no information that we can use to help.> > Note that NULL for the name value. I use as valid string but there is > goes as NULL. > > Do another scaffold named act and everything goes fine with no changes. > I could imagine that action is a reserved word but shouldn''t it complain > about it? > > Any hints?Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar Chron
2010-Nov-17 15:45 UTC
Re: Very confused - scaffold action does - sends NULL to db
comopasta Gr wrote in post #962162:> > Do another scaffold named act and everything goes fine with no changes. > I could imagine that action is a reserved word but shouldn''t it complain > about it? > > Any hints?I''d imagine that your use of a reserved word has caused the issue, so don''t. I am admittedly curious... (but too lazy to spin up my VM at the moment). What does the log show for the POSTed values? Unless you are willing to do the delving into the rails codebase, this is one of those simple "Don''t do that" cases. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-17 16:04 UTC
Re: Very confused - scaffold action does - sends NULL to db
Ar Chron wrote in post #962166:> comopasta Gr wrote in post #962162: >> >> Do another scaffold named act and everything goes fine with no changes. >> I could imagine that action is a reserved word but shouldn''t it complain >> about it? >> >> Any hints? > > I''d imagine that your use of a reserved word has caused the issue, so > don''t.I''d be surprised if "action" is reserved.> > I am admittedly curious... (but too lazy to spin up my VM at the > moment). > > What does the log show for the POSTed values? > > Unless you are willing to do the delving into the rails codebase, this > is one of those simple "Don''t do that" cases.Not necessarily. There''s not enough information yet to jump to that conclusion. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
comopasta Gr
2010-Nov-17 16:25 UTC
Re: Very confused - scaffold action does - sends NULL to db
Thanks guys, Of course I could paste all the code here. This uses the generated code by the scaffold generator. I haven''t changed a single line. Anyway, the main involved action is the create: # POST /actions # POST /actions.xml def create @action = Action.new(params[:action]) respond_to do |format| if @action.save format.html { redirect_to(@action, :notice => ''Action was successfully created.'') } format.xml { render :xml => @action, :status => :created, :location => @action } else format.html { render :action => "new" } format.xml { render :xml => @action.errors, :status => :unprocessable_entity } end end end Data from the view form: <%= form_for(@action) do |f| %> <% if @action.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@action.errors.count, "error") %> prohibited this action from being saved:</h2> <ul> <% @action.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> The relevant log lines: Started GET "/actions/new" for 127.0.0.1 at 2010-11-17 16:23:47 +0100 Processing by ActionsController#new as HTML Rendered actions/_form.html.erb (8.5ms) Rendered actions/new.html.erb within layouts/application (11.8ms) Completed 200 OK in 23ms (Views: 15.4ms | ActiveRecord: 0.0ms) Started POST "/actions" for 127.0.0.1 at 2010-11-17 16:23:53 +0100 Processing by ActionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"3uHroG5clvDouL8poeQKErZNEBlCA5s+Row3HXp8lEw=", "commit"=>"Create Action"} SQL (0.6ms) BEGIN SQL (1.1ms) describe `actions` SQL (0.3ms) INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'') SQL (0.7ms) COMMIT Redirected to http://127.0.0.1:3001/actions/1 Completed 302 Found in 61ms Yeah, might be a don''t do that :-) But usually it complain and doesn''t let you move on with reserved words so I was also curious. Also lazy to go deep since i can pick any other name and it goes ok. Cheers. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Colin Law
2010-Nov-17 17:00 UTC
Re: Very confused - scaffold action does - sends NULL to db
On 17 November 2010 15:29, comopasta Gr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, I''m a bit confused with this. > If you follow the steps below in Rails 3: > > 1- rails new act -d mysql > 2- rails g scaffold action name:string > 3- rake db:create > 4- rake db:migrate > 5- rails server > > when I add a record to that app I get: > > INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES > (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'') > > Note that NULL for the name value. I use as valid string but there is > goes as NULL. > > Do another scaffold named act and everything goes fine with no changes. > I could imagine that action is a reserved word but shouldn''t it complain > about it?According to the very useful page http://wiki.rubyonrails.org/rails/pages/ReservedWords: action – overwritten by Rails when used with form parameters (i.e. an ActionsController expecting action[field_name] won''t work) I fell over this one myself a little time ago. I ended up with Act model also. Colin> > Any hints? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
comopasta Gr
2010-Nov-17 17:31 UTC
Re: Very confused - scaffold action does - sends NULL to db
Yeah, reserved. First link in google sorry for that. I would have expected to see some complains from the framework though. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-17 17:45 UTC
Re: Very confused - scaffold action does - sends NULL to db
Colin Law wrote in post #962187:> On 17 November 2010 15:29, comopasta Gr <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> INSERT INTO `actions` (`created_at`, `name`, `updated_at`) VALUES >> (''2010-11-17 15:23:53'', NULL, ''2010-11-17 15:23:53'') >> >> Note that NULL for the name value. I use as valid string but there is >> goes as NULL. >> >> Do another scaffold named act and everything goes fine with no changes. >> I could imagine that action is a reserved word but shouldn''t it complain >> about it? > > According to the very useful page > http://wiki.rubyonrails.org/rails/pages/ReservedWords: > > action overwritten by Rails when used with form parameters (i.e. an > ActionsController expecting action[field_name] won''t work)Yes, I realized this just after posting. I couldn''t see why `action` as a field or Action as an object name would be reserved, but I didn''t take into consideration that Rails uses a parameter in the request with the same name as the object class. If that class is Action, then yes, bad things happen.> > I fell over this one myself a little time ago. I ended up with Act > model also. > > ColinBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.