actionview

How to pass multiple locals to a nested partial

倖福魔咒の 提交于 2019-12-04 12:49:46
This should be extremely straightforward and well documented, and I've done it several times, although there's something that's still killing me. I have a structure of partials calling nested partials. At some point one render call needs to pass an extra variable to the partial, although the rendering of the partial fails with a: undefined local variable or method `<variable name>' for #<#<Class:....> Here's my code for calling the render : = f.simple_fields_for :orders do |c| = render partial: "fields", locals: {f: c, step: f.object.step} though this doesn't work either: = f.simple_fields_for

Rails console - use image_tag method

*爱你&永不变心* 提交于 2019-12-04 10:49:49
问题 How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help! 回答1: Not sure why you're getting that error. It is strange. But the Rails Console exposes the helper methods through the helper variable. So this should work: helper.image_tag('test.png') 回答2: OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the config

Rails3 button_to is calling POST action, trying to call PUT action

半腔热情 提交于 2019-12-04 03:47:15
I have a button_to that I want to perform a PUT action (there is only one thing that can be updated about this resource - it will be updated as being 'acknowledged', so there are no other form fields associated with firing the action). This is in my view (the controller is given explicitly because the button is on a view that belongs to another controller): <%= button_to "Acknowledged", :controller => 'practice_sessions', :id => @practice_session.id, :method => :put %> In my routes file, the resource has been declared as a restful resource: resources :practice_sessions The controller for this

rails - how to render a JSON object in a view

白昼怎懂夜的黑 提交于 2019-12-03 15:24:43
问题 right now I'm creating an array and using: render :json => @comments This would be fine for a simple JSON object, but right now my JSON object requires several helpers which is breaking everything and requiring helper includes in the controller which seems to cause more problems than solved. So, how can I create this JSON object in a view, where I don't have to worry about doing anything or breaking anything when using a helper. Right now the way I'm making the JSON object in the controller

Nested Object w/ Checkboxes - mass-assignment even with accepts_nested_attributes_for?

有些话、适合烂在心里 提交于 2019-12-03 13:15:27
问题 I thought that there should have been a simple solution to this, given that Rails 2.3 has this newfangled nested forms feature. Basically I want to create or update a user and assign them roles at the same time. It seems like I'm doing everything right but I get the error WARNING: Can't mass-assign these protected attributes: roles_attrributes . I even tried changing the view to user[permissions_attrributes][role_id] because I thought that maybe the join table was confusing Rails. Anyways,

Using rails_admin with rails_api

╄→гoц情女王★ 提交于 2019-12-03 12:41:10
I originally posted this as an issue on rails_api GitHub , but am now posting it here due to inactivity. I'm trying to use rails_admin with a Rails 5 API application. I included extra ActionController modules up to the point that I can either have a functioning rails_admin panel or working API requests. The issue seems to be that rails_admin depends on ActionView::Layouts , which after included causes issues for API requests. Gemfile: gem 'rails', '>= 5.0.0.beta3', '< 5.1' ... gem 'rack-pjax', github: 'afcapel/rack-pjax' gem 'remotipart', github: 'mshibuya/remotipart' gem 'kaminari', github:

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

北城余情 提交于 2019-12-03 06:30:28
问题 I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar ). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( R.layout.action_view_layout, null); This appears to work fine. However; passing null for root in the call to inflate() makes Lint yell at me: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) I can seemingly

Rails console - use image_tag method

心已入冬 提交于 2019-12-03 06:07:29
How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help! Not sure why you're getting that error. It is strange. But the Rails Console exposes the helper methods through the helper variable. So this should work: helper.image_tag('test.png') OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the config.action_controller.asset_host = "http://..." config.action_mailer.asset_host = "http://..." in my environemnt file

rails - how to render a JSON object in a view

99封情书 提交于 2019-12-03 05:57:50
right now I'm creating an array and using: render :json => @comments This would be fine for a simple JSON object, but right now my JSON object requires several helpers which is breaking everything and requiring helper includes in the controller which seems to cause more problems than solved. So, how can I create this JSON object in a view, where I don't have to worry about doing anything or breaking anything when using a helper. Right now the way I'm making the JSON object in the controller looks little something like this? Help me migrate it to a view :) # Build the JSON Search Normalized

Nested Object w/ Checkboxes - mass-assignment even with accepts_nested_attributes_for?

人走茶凉 提交于 2019-12-03 04:06:53
I thought that there should have been a simple solution to this, given that Rails 2.3 has this newfangled nested forms feature. Basically I want to create or update a user and assign them roles at the same time. It seems like I'm doing everything right but I get the error WARNING: Can't mass-assign these protected attributes: roles_attrributes . I even tried changing the view to user[permissions_attrributes][role_id] because I thought that maybe the join table was confusing Rails. Anyways, any suggestions on how this should actually work? Model class User < ActiveRecord::Base has_many