Ruby on Rails
Thursday, May 1, 2014
On Wednesday, April 30, 2014 11:46:50 AM UTC-4, Kazuna Nakama wrote:
Thanks! So I renamed /views/background/randomize.html.erb to /views/background/_randomize. html.erb and changed the method name in the background controller to _randomize as well. I put <%= render :partial => "background/_randomize" %> in application.html.erb. Some things work, some things don't. So my randomize method simply sets @swf_bg to a random file in the public folder and then I put <%= @swf_bg %> in the _randomize.html.erb view. This is displayed properly when I go to /background/_randomize.html.erb, but when I go to the index of my site it's not including the @swf_bg variable that displays correctly when I go to /background/_randomize it's including the code from _randomize.hml.erb in my main page like: <embed src="" /> instead of <embed src="/random/swf/file.swf" />, but when I visit /background/_randomize in my browser it works fine.
2014年4月27日日曜日 15時59分57秒 UTC-5 mike2r:
On Saturday, April 26, 2014 2:45:58 PM UTC-4, Kazuna Nakama wrote:Hi Everyone, this is my first post on Ruby on Rails, I've managed to get up and running with Rails 4.1 on FreeBSD with Nginx and Ruby 2.1.1.My issue is this:I have a folder located at /public/swf/ that contains numerous swf files I want to load as a background for every page of my site. I've successfully created a controller with a randomize method and a corresponding view that loads the backgrounds randomly. The problem I'm having a bit of trouble with now is getting the output of /background/randomize.html.erb and putting that output into the application layout so the backgrounds load on every page. My HTML/CSS is just fine, however I can't seem to include that in the application view.Would I be using the render method, content_for, or capture do for taking the raw parsed HTML output of background/randomize and putting it in the application layout?I would rename randomize.html.erb as a partial and render it in the application layout. If you haven't worked with partials, refer to the following:mike
I probably should have anticipated that would be an issue. Partials are not templates, in fact, they are presumed to execute in the same controller/action as the template that calls them. They don't have their own corresponding actions.
I would have to test this, but I would probably define randomize as a protected method in the applications controller (and thus, would be inherited by all other controllers). I would then execute it as a before_action for those controller/actions that need it. I'd be interested in other suggestions on handling this. I'm not positive this would work, but I think that this would then work in the context of your partial.
Mike
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/43d66609-aa2c-46ad-8b2e-80cde73897f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment