I am creating an application in which I am allowing users to have
customized views of a form. These forms do not have to be customized
at this point by the user, but will for now be customized by us, and
uploaded to the server.
My idea was to take the similar approach done by the plug in
acts_as_attachment, and, have a default layout stored in the normal
views/controller_name folder, but then also have a check in the users
model to see if there is a customized view. If there was, the idea is
to place a subfolder under the views/controller_name folder, with the
id number of the user as the name of the folder, and place the
customized partial within and then have the software display that
partial, instead of the default one.
Im not sure if this is the best way of accomplishing this however, and
would welcome any suggestions. I have yet to find a plug in to
accomplish this.
If I do go this route, i cannot figure out how to have my main view
call a partial that is stored in a sub-folder. Is there a way of doing
this?
If I do go this route, i cannot figure out how to have my main view
call a partial that is stored in a sub-folder. Is there a way of doing
this?
render :partial => “subfolder/partial”
which you could enhance like that
render :partial => “#{@user.id}/partial”
would do the trick
i’m not sure if i would go that way, maybe storing
the users html in the database and inserting in the
page would be better, you could keep everything
on a code level without having to create per-user
directories in your view section (may depend on how
often you have to add users, and of course you could
write code to create a folder easy enough…)
maybe the public folder would be a better place to
store them if you have to…
Im am leaning towards storing the partials in the database. I agree
that im may begin to be a nightmare storing them in the file system,
and trying to keep everything in sync.
I have attempted to put this into the database, using the :text option
in my migration. What is the proper way to render this though? If I go
with <%= @member.name_of_partial %> it does not render the code, and
just places the text in the browser window.
Thanks again for your help!
On Feb 7, 12:46 pm, Thorsten M. <rails-mailing-l…@andreas-
@member.company_information is where the partial stored in the
database. @application is the instance variable that have to be passed
to the company_information partial.
In the application model I have the following method:
def get_binding
binding
end
The partial gets loaded, but the instance variables are not passed to
it. Am I right to be calling the get_binding from the Application
model?
Thanks!
On Feb 12, 1:45 pm, Thorsten M. <rails-mailing-l…@andreas-
first i’m not 100% sure, if run is the right command here
or if you should use result (easy enough, to try both)
the binding should not be that of application, as far as
i can make out from this question.
(is application an ActiveRecord model?)
as you use it, i think it would only bind to the
class level instance variables defined in Application
somewhere you use (controller?) @application = Application.new(…)
or @application = Application.find(…)
and that’s the place, from where you need the binding
(since that’s the binding, that contains the @application)
so most likely in the controller: @bind = binding @application = Application.new(…) # or whatever
and in the view:
<%= message.run(@bind)%>
hope that would do the trick, otherwise check step by step:
define a simple var (all in the view)
<% @test = “test” %>
<% message = ERB.new(@member.company_information) %> <-- this should
use @test
<%= message.run(binding)%> <-- just the binding of where we are
Some of the commands within the view, however, are not working. Is
there something else that I have to pass to the ERB to allow for
methods such as fields_for to work?
Here is a sample of what is in my view.
<% for email_address in @application.applicant.email_addresses %>
<% fields_for “credit_application[applicant_attributes]
[email_address_attributes][]”, email_address do |email_form| %>
<div id="ref_<%= reference_ix %>">
...
</div>
<% end -%>
How can I properly escape all of the double quotes and single quotes
as well as the variable injection (I think that is what it is called
– “#{reference_ix}”). I have attempted delimiting the string using
another character buy using %$ … $ but then it tries to interpret
the variable injection. Is there a function that can be used to easily
do this?
Thank for your help!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.