I just want to use link_to
to open a popup. I tried something but it doesn't work:
<%= link_to 'Create a new company',
new_company_path,
:popup => ['create_company', 'height=600, width=600'] %> <br/>
Any idea?
Thanks!
My first stab at this problem would probably look something like this. It assumes you're using rails 3, jQuery and jquery-rails. If you're not, this approach definitely won't work. This exact code isn't tested, so your mileage may vary. I'm just trying to give you an idea on how you might want to think about the problem. If you'd like me to elaborate on how this works, or have questions, let me know and I'll do my best to explain.
Turn your link_to into an ajax post:
<%= link_to "Create a new company", new_company_path, :remote => true, :method => :post %>
In your controller, respond with a javascript template:
def create
@company = Company.new(params[:company])
respond_to do |format|
if @company.save
format.js
else
format.js { render 'error' }
end
end
end
In views/companies/create.js.erb, execute the JS to open the new window.
window.open (<%= company_url(@company) %>, "mywindow","width=600,height=600");
And that should more or less do it, I think. I've had a few beers, so proceed with caution.