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: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 }
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

--
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@googlegroups.com.
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.

Search Discussions

  • Michael Pavling at Feb 16, 2012 at 12:37 am

    On 16 February 2012 00:32, Soichi Ishida 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?

    --
    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@googlegroups.com.
    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.
  • Michael Pavling at Feb 16, 2012 at 12:42 am

    On 16 February 2012 00:37, Michael Pavling wrote:
    On 16 February 2012 00:32, Soichi Ishida 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 #<Script>"
    message

    --
    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@googlegroups.com.
    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.
  • Soichi Ishida at Feb 16, 2012 at 1:01 am
    Thanks! It is fine now!

    soichi

    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 16, '12 at 12:32a
activeFeb 16, '12 at 1:01a
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Michael Pavling: 2 posts Soichi Ishida: 2 posts

People

Translate

site design / logo © 2022 Grokbase