Reputation: 495
I am having association group has_many events
I am having this method in show group view
= link_to 'Create Event', new_event_path(@group)
my new event method
def new
@event = Event.new(city: current_user.profile.city, group_id: params[:id])
end
It is showing unknown url localhost:3000/events/new.17
also group_id: params[:id] is not working
as i m new to ror please tell me reason thanks in advance
Upvotes: 0
Views: 33
Reputation: 9981
You don't specify parent resource therefore you can't use it as parameter in your new_event_path
URL helper and generate path like '/parent_resource/:parent_resource_id/events/new'. So, in you case just use any URL parameter i.e. group_id
:
= link_to 'Create Event', new_event_path(group_id: @group)
it will generate URL: /events/new?group_id=17
In this case the action will use group_id
parameter:
def new
@event = Event.new(city: current_user.profile.city, group_id: params[:group_id])
end
Upvotes: 1