Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails modify references
    text
    copied!<p>So my initial question was <a href="https://stackoverflow.com/questions/11572293/association-ruby-on-rails">Association Ruby on Rails</a>. However when referring to a post the issue that i am having is that its blank. Don't see anything. After researching I believe is because when i created my test post I didn't define a customer related to it.</p> <pre><code>class CustomersController &lt; ApplicationController before_filter :signed_in_customer, only: [:edit, :update] before_filter :correct_customer, only: [:edit, :update] def index @customers = Customer.all end def show @customer = Customer.find(params[:id]) **@posts = @customer.posts** end </code></pre> <p>Here the form that allow me to create a post for the moment.</p> <pre><code>&lt;%= form_for(@post) do |f| %&gt; &lt;% if @post.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@post.errors.count, "error") %&gt; prohibited this post from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @post.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :title %&gt;&lt;br /&gt; &lt;%= f.text_field :title %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :description %&gt;&lt;br /&gt; &lt;%= f.text_field :description %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :frienship_group_id %&gt;&lt;br /&gt; &lt;%= f.text_field :frienship_group_id %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :post_size_id %&gt;&lt;br /&gt; &lt;%= f.text_field :post_size_id %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Which is what i am using when creating a new form. How i am suppose to allow customization to update the field that this is related to the current user in the customer_id field?</p> <p>Here the model </p> <pre><code> class Post &lt; ActiveRecord::Base belongs_to :customer validates :title, presence: true validates :description, presence: true validates :customer_id, presence: true validates :frienship_group_id, presence: true validates :Post_size_id, presence: true </code></pre> <p>Update: </p> <p>Here my new.html.erb for post</p> <pre><code>&lt;h1&gt;New post&lt;/h1&gt; &lt;%= render 'form' %&gt; &lt;%= link_to 'Back', posts_path %&gt; </code></pre> <p>Here the controller</p> <pre><code>class PostsController &lt; ApplicationController # GET /posts # GET /posts.json def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.json { render json: @posts } end end # GET /posts/1 # GET /posts/1.json def show @post = Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @post } end end # GET /posts/new # GET /posts/new.json def new @post = Post.new respond_to do |format| format.html # new.html.erb format.json { render json: @post } end end # GET /posts/1/edit def edit @post = Post.find(params[:id]) end # POST /posts # POST /posts.json def create @post = Post.new(params[:post]) respond_to do |format| if @post.save format.html { redirect_to @post, notice: 'Post was successfully created.' } format.json { render json: @post, status: :created, location: @post } else format.html { render action: "new" } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # PUT /posts/1 # PUT /posts/1.json def update @post = Post.find(params[:id]) respond_to do |format| if @post.update_attributes(params[:post]) format.html { redirect_to @post, notice: 'Post was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # DELETE /posts/1 # DELETE /posts/1.json def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :no_content } end end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload