Reputation: 761
I'm new to rails development. This is my first app. And I've been struggling through it. Anyhow this is my issue. My modelname is PostIt and my controller is post_it_controller.rb
class PostItController < ApplicationController
def create
@user = User.find(params[:id])
@posts = Postit.create(params[:content])
@posts.receiver_id = params[:content][:receiver_id]
@posts.sender_id = current_user.id
end
and in my views I have this in create.html.erb
<%= form_for(@posts) do |f| %>
<%= f.hidden_field :receiver_id, :value => @user %>
<%= f.label :content %>
<%= f.text_area :content, :class => 'inputbox' %>
<%= f.submit "Submit", :class => 'btn right' %>
<% end %>
the error I keep getting is undefined method `model_name' for NilClass:Class
Upvotes: 0
Views: 125
Reputation: 4737
There are a few things in your code that break convention.
create
action is normally called when you submit the form with a POST
request.new.html.erb
or edit.html.erb
.PostItsController
.With that said, I think the error is due to @posts
being nil
. This may be because @posts
is being assigned in the wrong controller action, hence not being assigned at all by the time the response renders the form.
Upvotes: 1