Dans mon application ruby on rails, j'ai la vue standard dans chaque page qui donne une vue de navigation sur chaque page, mais j'ai un contrôleur de notifications que je souhaite utiliser sur chaque page donc théoriquement j'ai besoin de charger ce contrôleur et vue sur chaque page est-ce possibleContrôleurs Mutilple sur une page
ce <%= render 'shared/navigation' %>
rend une vue si aucune utilisation ce que im essayant de faire je lance un contrôleur dans un autre contrôleur essentiellement
Merci pour toute aide
ps . J'ai eu un bon coup d'oeil et ne trouve rien que les suites de ce im essayant de faire
Notifications Code contrôleur
class NotificationsController < ApplicationController
before_action :set_notification, only: [:show, :edit, :update, :destroy]
# GET /notifications
# GET /notifications.json
def index
@notificationlastid = Notification.last
# if the id params is present
if params[:id]
# get all records with id less than 'our last id'
# and limit the results to 5
@notifications = Notification.where('id > ?', params[:id]).where(userid: current_user.id)
else
@notifications = Notification.where(userid: current_user.id)
end
respond_to do |format|
format.html
format.js
end
end
# GET /notifications/1
# GET /notifications/1.json
def show
end
# GET /notifications/new
def new
@notification = Notification.new
end
# GET /notifications/1/edit
def edit
end
# POST /notifications
# POST /notifications.json
def create
@notification = Notification.new(notification_params)
respond_to do |format|
@notification.userid = current_user.id
if @notification.save
format.html { redirect_to @notification, notice: 'Notification was successfully created.' }
format.json { render action: 'show', status: :created, location: @notification }
else
format.html { render action: 'new' }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /notifications/1
# PATCH/PUT /notifications/1.json
def update
respond_to do |format|
if @notification.update(notification_params)
format.html { redirect_to @notification, notice: 'Notification was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end
# DELETE /notifications/1
# DELETE /notifications/1.json
def destroy
@notification.destroy
respond_to do |format|
format.html { redirect_to notifications_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_notification
@notification = Notification.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def notification_params
params.require(:notification).permit(:content, :description)
end
end
La seule façon de rendre de « plusieurs contrôleurs » sur la même page est d'utiliser AJAX.The contrôleur principal rend le côté serveur de page, d'autres morceaux de la les pages sont rendues par AJAX (en frappant d'autres contrôleurs). Je ne suis pas sûr d'avoir vraiment compris ce que vous essayez de faire. Que voulez-vous vraiment dire en utilisant plusieurs contrôleurs? – Codextremist
bien que j'ai fait un contrôleur pour la page de notifications mais je veux une boîte déroulante sur chaque page pour les notifications – Ray
Je pense que vous devriez déplacer votre méthode de contrôleur de notification au contrôleur d'application et utiliser des filtres pour l'appeler avant chaque action. Le code de vue peut être rendu en utilisant un partiel dans le fichier de disposition de l'application. – webster