I am trying to create a realtionship between two nodes as described here
https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Declared-Relationships
from_node.create_rel("FRIENDS", to_node)
I am getting an undefined method for create_rel
What am I doing wrong? I am trying to create a Q+A system inside another model. So both Questions and Answers are treated as models right now.
I'm getting a undefined method
create_rel' for #
event.rb
has_many :out, :event_questions
event_question.rb
has_one :in, :events
has_many :out, :event_answers
def create_questions_of(from_node,to_node)
from_node.create_rel("questions_of", to_node)
end
event_answer.rb
has_one :in, :event_questions
event_questions_controller.rb
def new
#is this needed
end
def create
@event_question = EventQuestion.new(event_question_params)
if @event_question.save
@event = Event.find(params[:id])
@event_question.update(admin: current_user.facebook_id)
@event_question.create_questions_of(self,@event)
redirect_to @event
else
redirect_to @event
end
end
private
def event_question_params
params.require(:event_question).permit(:question)
end
I have my new question sitting inside the event's index page since I wanted to list all the questions on the event after. I don't even need a new
method in my controller right? I also don't really know how I would obtain the event that my question form is sitting on. Is that accessible through params?
UPDATE
Did you mean this
def create_questions_of(to_node)
self.create_rel("questions_of", to_node)
end
and
@event_question.create_questions_of(@event)
So I think I need to change my routes as well and nest questions inside to create
events/123/questions/
Then I can grab events_id
and use find
UPDATE #2
events_controller.rb
def show
@event = Event.find(params[:id])
@event_question = EventQuestion.new
end
event.rb
has_many :out, :event_questions, type: 'questions_of'
event_question.rb
has_one :in, :events, origin: :event_questions
events/show.html.erb
<%= form_for [:event, @event_question] do |f| %>
#form stuff
<% end %>
event_questions_controller.rb
def create
@event_question = EventQuestion.new(event_question_params)
if @event_question.save
@event = Event.find(params[:event_id])
@event_question.update(admin: current_user.facebook_id)
@event_question.events << @event
redirect_to @event
else
redirect_to :back
end
end
routes.rb
resources :events do
resources :event_questions, only: [:create, :destroy]
end