partials

has_many through and partials

I have a User model, a Post model, and an Interest model. User has_many posts through interests User has_many interests Post has_many users through interests Post has_many interests Interest belongs to Post Interest belongs to User Application_Controller is as follows: class ApplicationController < ActionController::Base ...

How to render a Partial from a Model in Rails 2.3.5

I have a Rails 2.3.5 application and Im trying to render several Partials from within a Model (i know, i know -- im not supposed to). The reason im doing this is im integrating a Comet server (APE) into my Rails app and need to push updates out based on the Model's events (ex. after_create). I have tried doing this: ActionView::Base.n...

Rails 3 render :partials

Hi guys. I am migrating my 1.8.7 rails app to rails 3. But I have a problem with a partial: I have the following partial: in my cms controller : @clients = Client.all group = render_to_string :layout => 'layouts/window', :partial => 'clients/index' in my "clients/index" partial: <%= render :partial => 'clients/item', :collection ...

Auto generate HTML element IDs in Rails when repeating the same control through partials

Hello, I am using partials in Rails combined with jQuery child field templates to dynamically generate forms with multiple nested child attributes. Within these partials is JavaScript that is fired when various events (e.g. onChange) occur in the form, and the code that executes needs to change the DOM for a related but different form el...

Is it possible to bind an attribute to a forms_helper.select in a partial?

In a Rails view, I'm trying to show a <select> drop-down list for a number of different string fields with restricted values. I've been trying to do this with a partial (below), but the current value is not being selected in the <select> list. Is it possible to do this in a partial? If so, how? Is there a better approach to take? ...

Ajax form partials in Rails for multiple Models

I have this piece of AJAX code (took from: http://badpopcorn.com/blog/2008/09/11/rails-observer-field/) that is present in many views (new.html.erb and edit.html.erb mostly). To avoid code duplication I pretend to make use of partials: app/views/cities/_state_city_form.html.erb <p> State: <%= select(:state, :state_name, City.all(:sel...

Partial containing a form appears in both controllers, but fails to submit on one of them

I have a partial that contains a form: <% form_for :message, :url => { :action => "create" }, :html => { :id => 'form' } do |f| %> <%= f.error_messages %> <%= f.label :title, "title" %> <%= f.text_field :title %> <%= f.label :tag, "tag" %> <% if controller.controller_name == "tags" %> <%= f.text_field :tag_list, :value =...

Are helpers really faster than partials? What about string building?

I've got a fancy-schmancy "worksheet" style view in a Rails app that is taking way too long to load. (In dev mode, and yes I know there's no caching there, "Completed in 57893ms (View: 54975, DB: 855)") The worksheet is rendered using helper methods, because I couldn't stand maintaining umpteen teeny little partials for the different sor...

Rails Views: How do you pass a varaible to a partial layout?

In one of my views I apply a layout to a block of code: # In app/views/sessions/new.html.erb <% render :layout => 'home/shadow_box' do %> #... code for sign in form here <% end %> The layout is a div that has png shadows on all four sides. Since I use this layout all over my site, I want to pass a variable to the layout that spec...

mvc 2 help with xml partials

Ok, so in order to provide Data to Fusion Charts I need to give it some XML.. I have narrowed it down to this myChart.setDataXML("<%Html.RenderPartial("Graph", Model.graph_data); %>"); which renders myChart.setDataXML(" <chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' number...

How should partials be loaded when they are dependent on business logic?

I'm using the term "partial" to refer to a small section of presentational code which is repeated on many views. For example, a sidebar. In vanilla PHP, where the business and presentation logic is mixed, including a sidebar is no trouble: if($someCondition) { include('sidebar.php'); } However, in an MVC design pattern, the presen...

Rails 3 widget helper partial

Hi! I ran into a big problem in moving my application to Rails 3. I have a view helper which i call 'WidgetHelper'. It helps to render some partials automatically when i refer to it. For example <%= widget('loginbox', :global => true) %> But it not works correctly. It renders HTML code as I want, but escapes the return value, what is...

How can I split a HAML template into different partials/includes in PHP?

Hi All, I am a PHP dev trying to start using HAML, using this implementation: http://phphaml.sourceforge.net/ HAML looks awesome, but I don't understand if/how it supports partials (or includes, as they are called in the PHP world). I would like to have a master template HAML file that then goes and loads up a bunch of partials for al...

Haml render multiple partials in layout

app/views/layouts/shared.html.haml: = render :partial => "shared/head" = yield = render :partial => "shared/footer" app/views/shared/_head.html.haml: !!!XML !!!1.1 %html{"xml:lang" => "pl", :xmlns => "http://www.w3.org/1999/xhtml"} %head %title some title %body .container app/views/shared/index.html.ham...

Devise Custom Routes and Login Pages

I'm trying to get Custom Routes working in my Rails application (Ruby 1.9.2 with Rails 3). This is my config/routes.rb file match '/dashboard' => 'home#dashboard', :as => 'user_root' devise_for :user do get "/login", :to => "devise/sessions#new" # Add a custom sign in route for user sign in get "/logout", :to => "devise/sessions#...

Is it possible to render a partial and force the browser not to load from cache?

I have a window and when it opens, I need to make sure that the image is its latest state. So I thought why not.. render :partial => 'logo', :cache => false but that's not really rails. Any ideas? ...

How to implement the partial page loading functionality

Hi All, I have a application which has very bulky page and i can not reduce the functionality any more. Because of this my every page is taking too much time to load completely. Is there any way to load the page in sequential manner. Link once i hit the URL few content get displayed immediately and other contents will get displayed on...

Rendering an active menu element in a menu partial in rails 3

I have a dynamic submenu that is rendered according to which page the user is on. I placed the following code in a _sub_menu.html.erb partial: <a href="/dashboard/index" class="current">Index</a> <a href="/dashboard/account">Account</a> <a href="/dashboard/payments">Payments</a>` From my my main view, I call <%= render 'sub_menu' %>, ...