album/show.html.haml
#comment_list= render :partial => 'shared/comments', :locals => { :commentable => #album }
shared/_comments.html.haml
#comments
= commentable.comments.each do |comment|
= comment.content
display
Hello #<Comment:0x7f668f037710>
why is address displaying? How to remove it?
What happens if you remove the = before commentable?
I think the parser understand that you are mixIng erb and haml. Try removing = and inserting - instead.
Related
I am looking for displaying company logo in the email when email is sent. I went thought action mailer base and there is attachment inline feature which supports images in mail.
I implemented it in this way:
in user_mailer.rb
def welcome_email(user)
#user = user
#url = "http://mealnut.com"
attachments.inline['mealnut.png']
mail(:to => user.email, :subject => "Mealnut: New Order #{order.id}")
end
in config/application.rb:
config.action_mailer.default_url_options = { :host => "mealnut.com" }
in welcome_email.html.web
<div class="logo">
<%= image_tag attachments['mealnut.png'].url, :alt => 'Mealnut', :class => 'photo' %>
</div>
But it is giving error:
undefined method `url' for nil:NilClass
Whats going wrong?
attachments and inline attachments differs only that inline will insert it via base64 but you need to attach a file anyhow to it!
attachments.inline['mealnut.png'] = File.read( Rails.root.join("app/some/path/","mealnut.png") )
than you are able to reference it in the view
hope that helped!
I have this in my controller
...
..
render :js => "window.location = '/bar/ready'", :locals => { :foo => "foo" }
..
...
I want the <% foo %> variable and I want to access it in my HTML page.
but I cant seem to access it, as <%= params.inspect %> returns
{"controller"=>"bar", "action"=>"ready"}
So how can I pass the variable in my HTML page?
I needed something similar. Late, but I finally manage to do it doing:
render :js => "window.location = #{your_path(:foo => 'foo').to_json}"
And then parse json data in your view
I want to show comments tree. I moved comment div in another view, and wrote next line in _comments.html.haml :
= render :partial => 'single_comment', :collection => #post.comments.where(:parent_id => nil)
_single_comments.html.haml:
- if comment.id != nil
.comment
.meta
= comment.name
says
.body
= comment.text
.answers
= render :partial => 'posts/single_comment', :collection => #post.comments.where(:parent_id => comment.id)
But browser show me an error:
undefined local variable or method `comment' for #<#<Class:0x00000004e39280>:0x00000004e2f398>
Extracted source (around line #1):
1: - if comment.id != nil
2: .comment
3: .meta
4: = comment.name
I tried to add :as => comment in first line, but it doesn't work. So as a using #comment in partial.
Maybe it's fundamentally wrong?
You have to add :as => :comment on both render lines, remember the answers that are being rendered are rendering this same partial again, so they will try rendering answers too.
Try adding the :as => :comment on both the comments and the answers rendering part.
I'm trying to render the Devise edit password form within another view because I don't want to duplicate the edit pw logic.
I've tried the following (after generating the Devise views):
<%= render 'devise/passwords/edit' %>
<%= render 'devise/passwords/form' %>
And a number of other variations on render that all seem to give me the same error:
"ActionView::MissingTemplate in foo#foo
Missing partial devise/passwords/edit..."
This variation:
<%= render :file => 'devise/passwords/edit.html.erb' %>
Gave me some hope but the following error:
"undefined local variable or method `resource' for #<#:0x47ef0e0>"
around this line:
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
That makes me think I'm close (as that is code from the form that I want) but shouldn't that template be using the correct logic from the hidden Devise controller? Or do I need to do something in the routes file to get this to work?
Am I way off?
Try this:
<%= render :template => 'devise/passwords/edit',
:locals => {
:resource => my_user_model_variable,
:resource_name => my_user_model_name } %>
Where:
my_user_model_variable could be current_user
my_user_model_name could be "User"
I want to route requests something like this: reports/bloodtypes is routed to controller reports, action bloodtypes, with format = pdf, and the route named as bloodtype_report. The Guides gives an example
match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
When I do this:
match 'reports/bloodtypes' => 'reports#bloodtypes', :defaults => {:format => 'pdf'}, :as => 'bloodtype_report'
or this
match 'reports/bloodtypes' => 'reports#bloodtypes', :format => 'pdf', :as => 'bloodtype_report'
the controller still does not receive the :format => 'pdf' in params, and tries to render the report as HTML. The funny thing is that the route is shown by Rake as
bloodtype_report : /reports/bloodtypes(.:format) : {:format=>"pdf", :controller=>"reports", :action=>"bloodtypes"}
whether I use the first form (with :default) or second (just setting the format to pdf). It seems the route is correct, so why is the format parameter not being passed to the controller?
have you tried adding this to your controller:
respond_to do |format|
format.html
format.pdf { render :pdf => "show" }
end