Soichi Ishida
2012-Feb-16 00:32 UTC
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: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-/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.
Michael Pavling
2012-Feb-16 00:37 UTC
Re: Ajax save: Completed 500 Internal Server Error NoMethodError
On 16 February 2012 00:32, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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-/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.
Michael Pavling
2012-Feb-16 00:42 UTC
Re: Ajax save: Completed 500 Internal Server Error NoMethodError
On 16 February 2012 00:37, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 16 February 2012 00:32, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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-/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.
Soichi Ishida
2012-Feb-16 01:01 UTC
Re: Ajax save: Completed 500 Internal Server Error NoMethodError
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-/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.