Displaying 20 results from an estimated 3000 matches similar to: "Using helpers from controllers ?"
2007 Sep 30
2
Outputing to the browser, how?
Hello,
I''m writting some helper methods to write forms, so I have this working code:
class TableFormBuilder < ActionView::Helpers::FormBuilder
["file_field", "password_field", "text_field"].each do |name|
define_method(name) do |label, *args|
@template.content_tag(:tr,
@template.content_tag(:td,
@template.content_tag(:label,
2006 Feb 14
22
Teaching Models to Render Themselves in the Controller
I am trying to teach my models how to render themselves, i.e.
<%= my_model_object.render() %>
Let me explain my reasoning and proposed method before this gets shot
down as anti-MVC.
Let''s say I am writing a contact-management application. I have a
class Contact. I will need to display this class all over the
application. My first choice is to use a partial.
Now I can
2006 Feb 19
4
is "display" a reserved name of some sort?
A view display.rhtml sees no controller state variables set in the
corresponding display action. Why?
-- fxn
2006 Mar 23
3
Returning CSV data to the client
Hi,
One of my apps has to export data for the backend system to process it.
What''s the best way to create a CSV file in Rails and then return it as
a file to the client? i.e when they go to the link /csv/get_data it
would return a csv file.
I''ve been messing with the CSV library and I can get it to write out to
a file, but not sure how to best use this in a web app.
Hope
2006 Jul 13
1
From the Agile book, page 144 regarding a div tag helper
Hi. in the Rails Agile book here''s what was happening:
>>>
module StoreHelper
def hidden_div_if(condition, attributes = {})
if condition
attributes["style" ] = "display: none"
end
attrs = tag_options(attributes.stringify_keys)
"<div #{attrs}>"
end
# format_price method ...
end
Note that we cheated slightly here. We copied code from the Rails
2006 Feb 19
2
How far can you get without learning Ruby?
This has been my little experiment for the last few weeks. I jumped straight
into rails after a few tutorials and have been using "Agile Web Development
with Rails" as a reference. I picked up the Ruby syntax from examples which
was not hard to do as I know various other languages. I''ve started 3
database driven web apps and all was going really well. Rails is fun and
2006 Nov 16
2
Stubbing helpers
Hi,
Is it possible to stub out a helper for development?
I''ve got a (view) helper that renders a partial and runs all kind of
javascript. But for dev purposes I''d like it to return some hardcoded
html. I''m not having any success stubbing the helper out. Something
like...
test/mocks/development/helper_stub.rb
require ''application_helper''
class
2006 May 18
3
How to change CSV properties.....
Hello Good morning to all,
I am doing reports in ruby on rails,i am trying to export data throgh
excel in CSV format.Now i want to set the font to the text exported to
excel sheet.How can i set font..please help me regarding this ...
my sample code was like this...
report = StringIO.new
CSV::Writer.generate(report, '','') do |csv|
csv << [''Invoice History
2010 Feb 24
6
Yet another send_data :image question...
Guys & gals,
I''m also learning RoR (using v2.3.4). I''ve got a basic scaffold
working for image file creation, and - to a point - image file
display.
The send_data function is working in my controller - no problem. The
model code is able to parse the uploaded file construct too.
def show
@image = Image.find(params[:id])
send_data(@image.binary_data, :type =>
2005 Nov 16
19
Concerns over Rails' handling of tests
Sorry if this comes across as a bunch of disjointed thoughts...I''m just
trying to put my thoughts down and I''d like to know what other people''s
opinions on the subject are.
I''ve been working with Rails for 3 or 4 months now and I''m constantly trying
to look at ways of improving my testing techniques, especially when it comes
to TDD. I have a few
2006 Jul 24
2
InPlaceSelectEditor question
I''m attempting to use the example given in the Rails Recipes book chapter 2,
to create a select drop-down using the InPlaceEditor function (modified to
be InPlaceSelectEditor.
The example given works (a country list drop-down), but I''m attempting to
use it to display a list of items generated from an object in another table
that is linked to the table that I''m editing.
2006 Mar 14
5
Unable to display errors for multiple records
Hi,
I''m trying to save multiple records of the same model in one go. Which
is no problem at all. Problem starts when I want to introduce error
handling. The problem is that no record should be saved when one of the
records contains an error. I tried it as follows:
session[:infos].each do |info|
@quest.name = info["name"]
unless @quest.valid?
@errors_found = true
2006 Dec 17
12
Best practices for conditional display in views?
Hi.
I am writing an application that has a lot of boolean conditional
display logic, like this:
<% if user.description then %>
<p class="css_class"><%= user.description %></p>
<% end %>
Often the displayed content is more complex than the above, and to clean
up my views I am trying to pull a lot of this sort of thing into
partials.
However, the problem
2007 Aug 19
16
Possible memory leak problem...
I''m trying to figure out a possible memory leak problem I have in my
application.
I''ve tested both with mongrel and webrick and the problem remains. So
I think it''s not a mongrel problem, but I''m posting here to see if
anybody can help me.
The RAILS application is quite simple, no special plugins ( no
RMagick that has the memory problem ),
2006 Apr 04
26
Models accessing the session...
Can someone tell if there is a reason models shouldn''t access the
session?
Models could easily be made to access the session or some other shared
persistant data store such as a file or a table.
_This is the problem_, a model needs to know certain information eg. the
id of the current user. But the model has no idea about anything outside
of its self, because it can''t access
2011 Feb 09
16
rails 3.0.4 broke yield :javascript ?
hello,
I have today updated my rails app to 3.0.4 security release but now this
yield :javascripts
fails in the layout and I get my custom js escaped as text in the view.
anybody seeing this also?
tia,
jk
--
www.least-significant-bit.com
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to
2007 Jul 14
2
Using Helpers inside a Controller
I want to use helpers inside a controller method for an AJAX
application. After the page is loaded and displayed, there will be an
asynchronous javascript request to load additional resources such as
html forms and other data.
The controller which handles the request will collect the resources and
send them back in json format.
def get_resources
data=Hash.new
data[:form1]=form_helper1()
2006 Aug 12
7
Where should "business logic" reside in Rails?
Hi all,
What is the preferred location for my Business Logic? I have complex
business rules that go across a specific data model.
Are model classes primarily for record I/O and validations? Would
business logic classes also reside in ./app/models? Or would these
classes reside in the ./lib directory? (If not, what type of code goes
in ./lib?)
I am thinking about the differentiation of the
2013 Feb 03
4
Create a helper for models and views?
Hi!
If I have a method that is useful in both models and in views, where would
be the appropriate place to put it?
The method in question just takes two dates as strings, tries to parse them
and returns all dates in the range between them. It also takes care of the
issues when the dates are badly formatted etc etc..
This method is being used in several models (so a simple class method in
2006 Feb 18
4
Basic question: Where to initialize a flag?
I have found that if I initialize a flag in my controller (under def
Initialize), it appears everytime I call a controller action, the flag
is set to the initialize value (even though I''m not calling the
initialized action). Am I observing this clearly?
I don''t think I should initialize a flag in the index file. So where?
Specifically, I want to know if this action is a