ruby on rails

Problems displaying a list of my model instances  #angularjs #reactjs

  • } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions.
  • class ClientsController < ApplicationController before_action :set_client, only: [:show, :edit, :update, :destroy] # GET /clients # GET /clients.json def index @clients = Client.all end # GET /clients/1 # GET /clients/1.json def show end # GET /clients/new def new @client = Client.new end # GET /clients/1/edit def edit end # POST /clients # POST /clients.json def create @client = Client.new(client_params) respond_to do |format| if @client.save format.html { redirect_to @client, notice: 'Client was successfully created.'
  • in the application I have made, I have clients and projects.
  • Projects are made by first creating a client, and each project object is created via a client.
  • a Client has many projects and a project belongs to a client.

in the application I have made, I have clients and projects. a Client has many projects and a project belongs to a client. Projects are made by first creating a client, and each project object is created via a client.

@ng_real_ninja: Problems displaying a list of my model instances #angularjs #reactjs

class ProjectsController < ApplicationController before_action :set_project, only: [:show, :edit, :update, :destroy] before_action :set_client, only: [:new, :create] # GET /projects # GET /projects.json def index @projects = Project.all end # GET /projects/1 # GET /projects/1.json def show end # GET /projects/new def new @project = @client.projects.new end # GET /projects/1/edit def edit end # POST /projects # POST /projects.json def create #@project = Project.new(project_params) @project = @client.projects.new(project_params) respond_to do |format| if @project.save format.html { redirect_to @project, notice: 'Project was successfully created.' } format.json { render :show, status: :created, location: @project } else format.html { render :new } format.json { render json: @project.errors, status: :unprocessable_entity } end end end # PATCH/PUT /projects/1 # PATCH/PUT /projects/1.json def update respond_to do |format| if @project.update(project_params) format.html { redirect_to @project, notice: 'Project was successfully updated.' } format.json { render :show, status: :ok, location: @project } else format.html { render :edit } format.json { render json: @project.errors, status: :unprocessable_entity } end end end # DELETE /projects/1 # DELETE /projects/1.json def destroy @project.destroy respond_to do |format| format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_client #@project = Project.find(params[:id]) @client = Client.find_by(id: params[:client_id]) || Client.find(project_params[:client_id]) end # Never trust parameters from the scary internet, only allow the white list through. def project_params params.require(:project).permit(:client_id, :project_description, :project_timescale) end end class ClientsController < ApplicationController before_action :set_client, only: [:show, :edit, :update, :destroy] # GET /clients # GET /clients.json def index @clients = Client.all end # GET /clients/1 # GET /clients/1.json def show end # GET /clients/new def new @client = Client.new end # GET /clients/1/edit def edit end # POST /clients # POST /clients.json def create @client = Client.new(client_params) respond_to do |format| if @client.save format.html { redirect_to @client, notice: 'Client was successfully created.' } format.json { render :show, status: :created, location: @client } else format.html { render :new } format.json { render json: @client.errors, status: :unprocessable_entity } end end end # PATCH/PUT /clients/1 # PATCH/PUT /clients/1.json def update respond_to do |format| if @client.update(client_params) format.html { redirect_to @client, notice: 'Client was successfully updated.' } format.json { render :show, status: :ok, location: @client } else format.html { render :edit } format.json { render json: @client.errors, status: :unprocessable_entity } end end end # DELETE /clients/1 # DELETE /clients/1.json def destroy @client.destroy respond_to do |format| format.html { redirect_to clients_url, notice: 'Client was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_client @client = Client.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def client_params params.require(:client).permit(:name, :email) end end <%= form_for @project do |f| %> <% if @project.errors.any? %>

<%= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" %>

    <% @project.errors.full_messages.each do |msg| %>

  • <%= msg %>
  • <% end %>

<% end %> <%= f.hidden_field :client_id, value: @project.client.id %>

<%= f.label :client %>

<%= @project.client.name %>

<%= f.label :project_description %> <%= f.text_area :project_description %>
<%= f.label :project_timescale %> <%= f.text_field :project_timescale %>
<%= f.submit 'Save' %>

<% end %>

%h1 Editing project = render ‘project_form’ = link_to ‘Show’, @project \| = link_to ‘Back’, projects_path

%h1 Listing projects %table %thead %tr %th Client %th Project description %th Project timescale %th %th %th %tbody – @projects.each do |project| %tr %td= project.client.name %td= project.project_description %td= project.project_timescale %td= link_to ‘Show’, project %td= link_to ‘Edit’, edit_project_path(project) %td= link_to ‘Destroy’, project, :method => :delete, :data => { :confirm => ‘Are you sure?’ } %br = link_to ‘New Project’, new_project_path

%h1 New project = render ‘project_form’ = link_to ‘Back’, projects_path

%p#notice= notice %p %b Client: = @project.client.name %p %b Project description: = @project.project_description %p %b Project timescale: = @project.project_timescale = link_to ‘Edit’, edit_project_path(@project) \| = link_to ‘Back’, projects_path

ruby on rails