if statement - Use different variable depending on which view was used in Rails 4 -


i'm using mailboxer users can reply posts in site. there 2 types of post models in site users might reply to, requests , offers.

here messages controller:

class messagescontroller < applicationcontroller      # /message/new     def new         @request = request.find(params[:request])         @message = current_user.messages.new         @user = @request.user     end      def reply         @conversation ||= current_user.mailbox.conversations.find(params[:id])     end      # post /message/create     def create         @user = user.find(params[:user])         @body = params[:body]         @subject = params[:subject]         current_user.send_message(@user, params[:body], params[:subject])         flash[:notice] = "message has been sent!"         redirect_to :conversations     end end 

in new action, i'm using @request, if reply offer post, i'll need use @offer variable. there way can use if statement choose between @offer , @request depending on view new action called from? best way go this?

it's not graceful thing in world simple should work.

if params[:request]   @request = request.find(params[:request]) else   @offer = offer.find(params[:offer]) end 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -