Cloud9で簡単なブログの作成をしています。
体裁はともかく機能は全て実装したつもりなのですが、アプリから新規作成と更新ができない状況です。
(画面遷移と削除は可能)
formボタンを押した際に通信が発生している様子がなく、パラメータが取得できず、画面も遷移しません。
念のためサーバーの再起動は実施済みです。
consoleからデータを更新することは可能であること、またエラー画面の表示もないことから、
viewのform設定がおかしいのではないかと思うのですが、ご確認いただけないでしょうか。
よろしくお願い致します。
<% if @blog.errors.any? %> <p>you've got <%= @blog.errors.count %> ERRORs!</p> <% @blog.errors.full_messages.each do |error| %> <ul> <li><%= error %></li> </ul> <% end %> <% end %> <table> <%= form_with(model: @blog, local: true) do |form| %> <tr> <th><%= form.label :"title" %></th> <td><%= form.text_field :title %></td> </tr> <tr> <th><%= form.label :"content" %></th> <td><%= form.text_area :content %></td> </tr> <td><%= form.submit "submit." %></td> <% end %> </table> <p class="back_to_index"><%= link_to "back.", blogs_path %></p>
こちらがcontrollerです。
class BlogsController < ApplicationController before_action :find_blog_by_id, only:[:show, :edit, :update, :destroy] def index @blogs =Blog.all end def new @blog = Blog.new end def create @blog = Blog.new(blog_params) if @blog.save redirect_to blogs_path, notice: "created new blog \"#{@blog.title}\"." else render "new" end end def show end def edit end def update if @blog.update(blog_params) redirect_to blogs_path, notice: "edited blog \"#{@blog.title}\"." else render "edit" end end def destroy @blog.destroy redirect_to blogs_path, notice: "deleted blog \"#{@blog.title}\"." end private def blog_params params.require(:blog).permit(:title, :content) end def find_blog_by_id @blog = Blog.find(params[:id]) end end
回答1件
あなたの回答
tips
プレビュー