I'm converting an application from rails 2 to rails 3 and could somebody please help me regarding this small bit of code. The link_to is not working , could some one point me how to use link_to instead of the link_to_remote in rails 3.1 properly? Rails 2 code
<%= link_to_remote package_item.getId(),
:url => { :controller => 'cmn/popup',
:action => "show_popup",
:frame_url => admin_url(
:ctrl => controller,
:app_action => 'package.item.edit',
:id => package_item.getId().to_s,
:remote => true
),
:frame_width => '570px',
:frame_height => '355px'
}
%>
Rails 3.1 code
<%= link_to package_item.getId(),
:url => { :controller => 'cmn/popup',
:action => "show_popup",
:frame_url => admin_url(
:ctrl => controller,
:app_action => 'package.item.edit',
:id => package_item.getId().to_s
),
:frame_width => '570px',
:frame_height => '355px',
:remote => true
}
%>
I replace all .rjs
file with .js.erb
. This is the URL I'm getting in Rails 3:
<a href="/common/login/en/sentry?url%5Baction%5D=show_popup&url%5Bcontroller%5D=cmn%2Fpopup&url%5Bframe_height%5D=355px&url%5Bframe_url%5D=%2Fcommon%2Flogin%2Fen%2Fsentry%3Fapp_action%3Dpackage.item.edit%26id%3D3%26remote%3Dtrue&url%5Bframe_width%5D=570px&url%5Bremote%5D=true">3</a>
This is in Rails 2:
<a href="#" onclick="new Ajax.Request('/cmn/popup/show_popup?frame_height=355px&frame_url=%2Fcmn%2Fcmn%2Findex%2F2%3Fapp_action%3Dpackage.item.edit%26amp%3Bbrand%3Dsentry%26amp%3Blanguage%3Den&frame_width=570px', {asynchronous:true, evalScripts:true}); return false;">2</a>
my controller
def show_popup
@content_data = {}
@content_data.merge!(params)
render(:template => 'cmn/popup/show_popup', :nolayout => 1)
end
Please look at the syntax of
link_to
in Rails 3: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_toYou have all your parameters in a
:url
hash, but you don't need to name it:url
, just pass in the options in a hash, like this:Remember to get
:remote
out of the url hash.Let me know if this works.