Rails: Rendre un .js.erb d'un autre contrôleur?
Comment puis-je rendre une .js.erb
à partir d'un contrôleur qui n'appartient pas à la vue, il va être rendu?
Par exemple: Comment puis-je rendre create.js.erb
dans mes pages à afficher, à partir d'un post_controller
?
post_controller.rb
def create
@post = Post.new(post_params)
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render action: 'show', status: :created, location: @post }
format.js #{I think I need something in here?}
else
format.html { render action: 'new' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
source d'informationauteur allegutta
Vous devez vous connecter pour publier un commentaire.
Il semble qu'il y a plusieurs façons d'y parvenir:
Comment avez-vous respond_to un autre fichier js dans le contrôleur à l'aide de Ruby on Rails?
Rendre de vue alternatif dans ruby on rails