私は非常に新しいルビーレールです!私は基本的に、組織がイベントを作成できるアプリケーションを作成しようとしています!未定義のローカル変数やメソッドが `ルーティングエラーEventsControllerはparamsは:彼らは私がこれエラーが取得イベントを作成しようとすると、ユーザーが組織を作成することができますが、これまでのところ、クラスRuby on Railsルーティングエラー
私はすべての上に見てきたし、あなたは私に教えてください何か提案があれば、スタックオーバーフローの上に似たような何かを見つけようとしました!
イベント・コントローラ: before_action @organization = Organization.find(paramsは[:ORGANIZATION_ID])
def index
@events = @organization.events
end
def show
@event = Event.find(params[:id])
end
def new
@event = Event.new
end
def create
@event = Event.new(event_params)
@event.organization = @organization
if @event.save
redirect_to organizations_path
else
render 'new'
flash[:notice] = "Event not saved"
end
end
def edit
@event = Event.find(params[:id])
end
def destroy
@event = Event.find(params[:id])
@event.destroy
redirect_to organizations_url
end
private
def event_params
params.require(:event).permit(:user_id, :organization_id, :event_size, :date, :name, :description, :location)
end
end
組織コントローラ
<h1>Events index</h1>
<% @events.each do |event| %>
<div class="events_name">
<p><%= event.name %></p>
<p><%= event.description %></p>
<p><%= event.location %></p>
<br/>
<% end %>
</div>
index.html.erb
def index
@organizations = Organization.all
# @organization = Organization.find(params[:id])
end
def show
@organization = Organization.find(params[:id])
@events = @organization.events
end
def new
@organization = Organization.new
end
def create
@organization = Organization.new(organization_params)
if @organization.save
redirect_to organizations_path
else
render "new"
end
end
private
def organization_params
params.require(:organization).permit(:organization_id, :name, :description, :location, :volunteer_position)
end
end
イベント
ルート
Rails.application.routes.draw do
root 'home#index'
resources :timeslots
resources :sessions, only: [:new, :create, :destroy]
resources :users
resources :home
resources :home, only: [:index]
resources :organizations do
resources :events
end
最初のコメントにあなたの応答に基づいてイベント
<%= form_for @event do |f| %>
<div>
<%= f.label :name %>:
<%= f.text_field :name %><br />
</div>
<div>
<%= f.label :description %>:
<%= f.text_field :description %><br />
</div>
<div>
<%= f.label :location %>:
<%= f.text_field :location %><br />
</div>
<div>
<div class="field">
<%= f.label :date%>
<%= f.date_select :date,
{ order: [:month, :day, :year],
prompt: [ day: 'Select day', month: 'Select month', year: 'Select year' ]} %>
</div>
<br>
<%= f.submit %>
<% end %>
はEventsController'がApplicationController' ''継承のですか? – MaicolBen
いいえ、それはすべきです(遅く返事を申し訳ありません!)? –
ビューからコントローラに渡されたパラメータを投稿できますか?それはログに記録されます。また、イベントフォーム – Pramod