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’)
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?
try added mannually using rails console
$ Action.create(:name => “name example”)
and, post result.
att: Luciano S.
http://www.lucianosousa.net
http://www.lucianosousa.nethttp://twitter.com/lucianosousa
*Ruby on Rails Developer
*Linux User #456387
*Contato: (21) 8418-5945
2010/11/17 comopasta Gr [email protected]
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.
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
[email protected]
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
[email protected]
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? %>
<%= pluralize(@action.errors.count, “error”) %> prohibited
this action from being saved:
<ul>
<% @action.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% 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.
Yeah, reserved. First link in google sorry for that.
I would have expected to see some complains from the framework though.
Thanks!
On 17 November 2010 15:29, comopasta Gr [email protected] 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)
I fell over this one myself a little time ago. I ended up with Act
model also.
Colin
Colin L. wrote in post #962187:
On 17 November 2010 15:29, comopasta Gr [email protected] 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.
Colin
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]