Ajax save: Completed 500 Internal Server Error NoMethodError

Rails 3.1.3

I get the following error when Ajax ‘save’ action is executed.

Started POST “/scripts” for 127.0.0.1 at 2012-02-16 09:23:05 +0900
Processing by ScriptsController#create as JS
Parameters: {“utf8”=>“✓”,
“authenticity_token”=>“9rMiPwxlQrXiAIgUy8Qqe77KXDezXmpLF4WLupZb5ME=”,
“script”=>{“video_id”=>“18”, “startp”=>“37”, “text”=>“eeeeee”},
“commit”=>“save”}
(0.1ms) SELECT 1 FROM “scripts” WHERE “scripts”.“startp” = 37 LIMIT
1
Completed 500 Internal Server Error in 15ms

NoMethodError (undefined method script' for #<Script:0x00000103202868>): app/controllers/scripts_controller.rb:44:inblock in create’
app/controllers/scripts_controller.rb:43:in `create’

It says ‘NoMethodError’, but in the controller,

def create
@script = Script.new(params[:script])
respond_to do |format|
if @script.save #<=44: HERE!!!
format.html { redirect_to @script, notice: ‘Script was
successfully added.’ }
format.json { render json: @script, status: :created, location:
@script }
else
format.html { render action: “new” }
end
end

‘script’ is not defined? I have no clue.

save.js.erb has the following.

$('#listtrans').html('<%= escape_javascript(render :partial =>

“script_list”, :locals => {:scripts => @video.scripts} ) %>’);

Does anyone have any clue?

soichi

On 16 February 2012 00:32, Soichi I. [email protected] wrote:

It says ‘NoMethodError’, but in the controller,

def create
@script = Script.new(params[:script])
respond_to do |format|
if @script.save #<=44: HERE!!!

What does the Script model look like?

Thanks! It is fine now!

soichi

On 16 February 2012 00:37, Michael P. [email protected] wrote:

On 16 February 2012 00:32, Soichi I. [email protected] wrote:

It says ‘NoMethodError’, but in the controller,

def create
@script = Script.new(params[:script])
respond_to do |format|
if @script.save #<=44: HERE!!!

What does the Script model look like?

Don’t worry… I found it in your other thread.

I think your problem may be the validation in the Script:

class Script < ActiveRecord::Base
belongs_to :video
has_many :users

validates :startp,
:presence => true,
:uniqueness => true, #HERE!!!
:numericality => { :only_integer => true, :less_than => 1000}

validates :script,
:presence => true
end

The “validates :script, :presence => true” should be “validates
:video” shouldn’t it? You don’t have another “script” associated with
the script - hence the “undefined method `script’ for #”
message