3

I pass parameter with url called var which is containing value 'event'. I want to check this variable in rjs file and load a modal dialog box. Following is my code.

page<<" if (:var== "event") {"
page<< "$j ('#create_evnt_dialog').dialog({
    title: 'New Trainer',
    modal: true,
    width: 500,
    close: function(event, ui) { $j ('#create_evnt_dialog').dialog('destroy') }

 });"
page << '}else{'
page.replace_html 'create_evnt', :partial => 'add_events'
page << "}"

I could not check variable event in rjs file.how can i do this?

This is my Ajax link ::

<%= link_to_remote 'Add new event', :url => {:controller => 'events', :action => 'new' }, :with=>"'var=' + escape('event')" %>

<%= link_to_remote 'Add new holidays', :url => {:controller => 'events', :action => 'new' }, :with=>"'var=' + escape('holy')" %>

This is my controller code ::

def new
@event = Event.new
@trainers= Trainer.all
@countries= Country.all
@venues= Venue.all

@var=params[:var]

if(@var == 'holy')
    @event.trainer_id='0'#If we save holiday as event we put 0 to trainer and venue
    @event.venue_id='0'  
end
end
Rosh
  • 730
  • 2
  • 12
  • 32

2 Answers2

4

Just you can use

    if params[:template] == "viewer"
      render :action => "viewer_destroy.js.rjs"
    else
      render :action => "destroy.js.rjs"
    end
SL_User
  • 1,934
  • 5
  • 24
  • 45
0

I think you have to use ruby syntax like this:

if (<%= :var %> == "event") {

or all in ruby

<% if :var == "event" %>

<% end %>
Nima Izadi
  • 996
  • 6
  • 18