before_filter :protect, :load_post
private
def load_post
id=session[:user_id]
Question.find_each do |@que|
if(@que.user_id == id) # id is user id
@que_id = "#[email protected]}" #que_id is question_id
break
end
end
#flash[:notice] = @que_id
@question = Question.find(@que_id)
i...@que_id
#flash[:notice] = idd
iddd=idd.to_i
Post.find_each do |@pos|
if(@pos.question_id == iddd) # id is question id =>
{iddd || @que_id.to_i}
@pid = "#[email protected]}" #pos_id is id in posts table
#flash[:notice] = @pid.to_s
break
end
end
@post = Post.find(@pid)
@post = Post.find(params[:idd])...........(1)
end
Sir, even if i comment the entire lines in the prog and juzz keep eqn
(1) which contains the "idd" and then execute the code, it says cannot
find Post without an ID when @post = Post.find(params[:idd]) has that id
of the post..
What could the reason be for the same?
def create
#...@post = $n
@answer = Answer.new(params[:answer])
@answer.user = User.find(session[:user_id])
@answer.post = @post
inc = 0
Answer.find_each do |@aid|
inc = @aid.id.to_i #que_id is question_id
end
cnt = inc + 1
@answer.answer_id = cnt
#flash[:notice] = "User ID is " + session[:user_id].to_s
@answer.question_id = @que_id.to_i
@post.answer_id = cnt
respond_to do |format|
if @answer.duplicate? or @post.answers << @answer
flash[:notice] = 'Answer is Posted Successfully!.'
format.html { redirect_to post_url(:id => @post) }
format.xml { head :created, :location => post_url(:id => @post)
}
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors.to_xml }
end
end
end
This is the create action..where @post is required..Please help sir..
Thank yuh for ur worthy guidance!
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.