开发者

how to use if condition in rjs?

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 =&g开发者_如何学Pythont; '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


Just you can use

    if params[:template] == "viewer"
      render :action => "viewer_destroy.js.rjs"
    else
      render :action => "destroy.js.rjs"
    end


I think you have to use ruby syntax like this:

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

or all in ruby

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

<% end %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜