post_controller.rb
以下ーーーーーーーー
class PostsController < ApplicationController
def index
@posts = Post.all
end
中略
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path
else
render action:'new'
end
end
end
ここまでーーーーーーーーーーーーーーー
new.html.erbは、
以下ーーーーーーーーーーーーー
<h1>New Post</h1>
<%= form_for(@post) do|f| %>
中略ーーー
<div class="actions">
<%= f.submit %>
</div>
<% end %>
ここまでーーーーーーーーーーーー
となっております。調べている感じ、おそらくruby4.0バージョンによる問題かなと思っております。以下ソース(http://www.alfajango.com/blog/rails-4-whats-new/)しかし、結局どこに問題があるかわからないので、もしよければご回答お願い致します。
既に qixil で回答が付いているように Ruby on Rails 4 で追加された Strong Parameters という仕組みによってはじかれてます。
プログラムの方で、「このパラメータは、受け付けるよ!」って、明示的に書いてあげないと ActiveModel::ForbiddenAttributesError が飛んできます。
Furthermore, in the above example, if you try to pass unpermitted params from the controller to the Post model, it'll raise an ActiveModel::ForbiddenAttributesError.
http://www.alfajango.com/blog/rails-4-whats-new/
具体的には、
def create @post = Post.new(post_params) ... end private def post_params params.require(:post).permit(:title, :body) end
とか、
def create params.permit! @post = Post.new(params[:post]) ... end
とか、のように変更する必要があります。。
# 自分で使ってないので、はっきりとは分かりません m(_ _)m
で、ヴァージンを自認(って、筆卸は済んでますよね :-)するのであれば、お姉さんドットインストールのレッスンが言ってることに合わせた方が、何かと揉め事が少なくて済みます。
ここを何とか切り抜けても、また別の文句を言われる可能性は、非常に高いので。
動画中で使用されている技術
Ruby on Rails 3.2.3 Ruby 1.9.3 gem 1.8.23 SQLite 3.3.6
http://dotinstall.com/lessons/basic_rails
素直に、お姉さんドットインストールのレッスンが言うように、バージョンを合わせた方が良いです。
ぴちぴちの新しい方が良いんだ、ということであれば古いバージョンを前提にしたレッスンではなく、他の教材を探した方が良いと思います。
コメント(1件)
ruby のバージョンが 1.9.3
rails のバージョンが 4.0
じゃないかなぁ。