Trouble on rendering a template passing a local variable
:locals => { :user => @current_user }
and in template
Name: <%= user.name %>
Local variables are local, so you don't need @
to refer them.
@user502052
You can render view explicitly from your controller.
render :template => "users/show", :locals => {...}
When you don't execute render
in controller, framework does that for you with default parameters. When you do, you can specify different template file, pass local variables, render a partial: anything render
function supports.
Missing template when rendering a collection using local variables
If you're trying to render the same partial at app/views/categories/_category.html.erb
you need to change your render
call for your organization's show
template.
render partial: "categories/category", collection: @categories, ...
The app/views/organizations/show.html.erb
template will otherwise look for a file at app/views/organizations/_category.html.erb
.
Is it possible to render a partial by passing a local variable for the collection?
Please try it
<%= render partial: 'item_kanban', collection: items, as: :item %>
Now you can access
<%= link_to item, class: "list-group-item" do %>
<%= item.number %>
<% end %>
When you did
<%= render partial: 'item_kanban', collection: items %>
will give you a item_kanban
local variable and not a item
variable.
So you need to specify it by as: :item
now you can access item
Error when rendering a partial (RoR) passing the form as a local variable
That's weird. It should work as you have it with :form or :f. If you're using Ruby 1.9, maybe there's some difference in how local variables work. I would try :locals => { "f" => f }
with a string key instead of symbol and see if that helps. Also, does it work to use a simpler case like :locals => { :x => 2 }
?
rails 4.1 - rendering nested partial in JS template - local variable issue
Change your contents partial to this
<div id="contents">
@contents.each do |c|
<%= render partial: "content", locals: {c: c}
end
</div>
Your content partial would be like this:
some html ... (image being rendered by amazon s3/cdn)
<%= render 'action_buttons', :c => c %>
Now in your create.js.erb file you will have this code:
$("#contents").append("<%=j render partial: 'content', locals: {c: @content} %>");
Update:
You can't update just actions as it's inside a loop so you have two options either to render your whole partial again or use js to target your buttons and change there content but since you don't want to render your whole partial so you are left with second option. To update links content your create.js.erb would be like this:
$("#contents").append("<%=j render partial: 'content', locals: {c: @content} %>");
$(".follow").text('following'); // give class to all of your follow buttons and then change there content to following
Related Topics
Automatically Precompile Assets Before Pushing to Heroku
Ruby on Rails User Registration Using Rest API Call and Devise
Has Anyone Figured Out a Way to Run the Same Cucumber Scenario on Multiple Browsers/Web Drivers
Checking If a String Is Valid JSON Before Trying to Parse It
Begin Rescue Not Catching Error
Ruby Code Beautification, Split Long Instructions on Multiple Lines
How to Stop God from Leaving Stale Resque Worker Processes
Rails Return JSON Serialized Attribute With_Indifferent_Access
Differences Between Literals and Constructors? ([] VS Array.New and {} VS Hash.New)
How to Set a Request.Referrer Inside My Rspec
How to Use the Ruby "Self" Keyword
How to Embed Ruby in JavaScript (Rails + .Html.Erb File)
How to Get Rspec to Run All Tests Nested Under a Folder
Rails - Paperclip Validating Attachment Size When It Shouldn't Be