respond with - Rails: respond_with not working properly during create action -


here create method in controller (old way):

  def create     @athlete = athlete.find(params[:video][:athlete_id])     @video = video.new(params[:video])      if @athlete.can_add_another_video? && @video.save       flash[:notice] = "successfully created"       pandaworker.perform_async(@video.id)       log_activity(@video.logging_information)     else       flash[:notice] = @video.errors.full_messages.to_sentence     end      respond_with @video, location: athlete_profile_showcase_path   end 

new way:

  def create     @athlete = athlete.find(params[:video][:athlete_id])     @video = video.new(params[:video])      if @athlete.can_add_another_video? && @video.save       flash[:notice] = "successfully created"       pandaworker.perform_async(@video.id)       log_activity(@video.logging_information)       respond_with @video, location: athlete_profile_showcase_path     else       flash[:notice] = @video.errors.full_messages.to_sentence       redirect_to athlete_profile_showcase_path     end   end 

the first piece of code above fails if saving of video object doesn't happen. attempts redirect videoscontroller#new method instead of following location specified. first way wrong, not sure why. appreciated! still trying understand respond_with syntax

specified 'location' used when model valid. have @ responder docs custom options need. check answer here - defining custom responder can more cleaner.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -