PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 17, 2022

[FIXED] How display my view with partials in Rails?

 May 17, 2022     partial, ruby, ruby-on-rails     No comments   

Issue

I'm learning Rails and I'm trying to use partials to clear my code.

When I refresh the post/new page, the only thing I have is the "Créer un article". Nothing in my partial _form appears..

I don't understand my mistake, did I miss something?

Here is my view:

<h1>Créer un article</h1>

<%= render 'form' %>

Here is the partial:

<% form_with model: @post do |f| %>
  <div class="form-group">
    <label>Titre</label>
    <%= f.text_field :title, class:'form-control' %>
  </div>
  <div class="form-group">
    <label>Slug</label>
    <%= f.text_field :slug, class:'form-control' %>
  </div>
  <div class="form-group">
    <label>Contenu</label>
    <%= f.text_area :content, class:'form-control'%>
  </div>
  <div class="form-group">
    <%= f.submit "Valider", class: "btn btn-primary" %>
    <a href="<%= posts_path %>" class="btn btn-secondary">Retour</a>
  </div>
<% end %>

Log from rails local server:

Started GET "/posts/new" for ::1 at 2019-12-26 17:38:03 +0100
Processing by PostsController#new as HTML
  Rendering posts/new.html.erb within layouts/application
  Rendered posts/_form.html.erb (Duration: 20.7ms | Allocations: 2408)
  Rendered posts/new.html.erb within layouts/application (Duration: 22.8ms | Allocations: 2711)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 40ms (Views: 34.5ms | ActiveRecord: 0.0ms | Allocations: 7669)

Solution

you missing equal sign (=) from first line, it should be like this below

<%= form_with model: @post do |f| %>


Answered By - widjajayd
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing