<% if logged_in? and post.match?(post.id) %>
          <%= $n = post.id %>
          <%= link_to "Answer this Query!",
          :controller => "answers",
          :action => "new",
          :idd => post.id %>

Hello sir,
   In the example given above, i am calling a new method to answer the
query submitted by the user for the "idd" ie. according to the "id" of
the question.
Bt i cant get this id in the answer_controller which i want..
i hav even declared a global variable in the program which tracks the
post id..
can u please help me in accessing the "idd" when the user clicks the
link and goes to the action "new" page.
I want the "particular id of the post that has been posted by the user
as i am getting the array of post id's but not the id of the particular
post when i click it.
Please Help..
Following is my code in answer controller..




$x = 0
class AnswersController < ApplicationController
helper :profile, :avatar
include ProfileHelper
include AvatarHelper
before_filter :protect, :load_post

  def new
  #flash[:notice] = post.id
  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
     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
    #flash[:notice] = id

    @posts = Post.find(@pid)
    @post = Post.find(params[:idd])

    @answer = Answer.new
    @title = "Post your Answer Here!"
    #...@post = @posts

    $x = @post.id
    mm = $x
    #flash[:notice] = mm

    @post = mm

  end


  def create
    @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

 def destroy
   @answer = Answer.find(params[:id])
   user = User.find(session[:user_id])
   if @answer.authorized?(user)
      @answer.destroy
   else
     redirect_to hub_url
     return
   end
   respond_to do |format|
    format.html { redirect_to posts_url }
        format.xml { head :ok }
    end
 end

private

  def 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) ................................EQN [1]
  end

end


Sir here as i hav marked here EQN[1] which suggests that i want the row
in the posts table to be collected in instance variable @post.
Bt the row should correspond to "idd => post.id"
ie. @post should contain id of the post when i click the link.


Also when i click i want to get the ques_string corresponding to the
post.id
i.e. I want @post.ques_string which it says "ques_string" is undefined?
Waiting for ur Reply...
-- 
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.

Reply via email to