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 at 2012-02-16 09:23:05 +0900
  Processing by ScriptsController#create as JS
  Parameters: {"utf8"=>"✓",
"script"=>{"video_id"=>"18", "startp"=>"37", "text"=>"eeeeee"},
   (0.1ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 37 LIMIT
Completed 500 Internal Server Error in 15ms

NoMethodError (undefined method `script' for
  app/controllers/scripts_controller.rb:44:in `block 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 }
        format.html { render action: "new" }

'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?


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

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 #<Script>"

Thanks! It is fine now!