Questions tagged [view-components]

37 questions
6
votes
1 answer

Create a View Component template/container that accepts HTML or other components as parameters

I have searched many places and have not seen anything similar to what I am thinking. Let's say I want to create a reusable container component, like a card, form, or a modal, and save that as a View Component. How would I add a new view components…
5
votes
2 answers

Tailwind CSS responsive classes not working with Rails ViewComponent gem

I'm using the ViewComponent gem with Tailwind CSS. I render components from my view files with <%= render ExampleComponent.new(resource: @resource) %>. In my app/components directory, I have example_component.rb and example_component.html.erb…
5
votes
1 answer

How can I avoid naming my View Component cshtmls "Default.cshtml" in ASP.NET Core MVC?

It seems that in ASP.NET Core MVC, if I want to use a View Component, I have to put them in Views\Shared\Components\[ViewComponentName], and then name the file "Default.cshtml". This is rather frustrating, as in the beginning of a large project I am…
3
votes
1 answer

Rails viewcomponents test render? in RSpec

Rails Viewcomponents allow you to test if a component has rendered in minitest using refute_component_rendered but how do you do the same in RSpec? class SometimesNotRenderedComponent < ViewComponent::Base def initialize(my_param) @my_param =…
notapatch
  • 6,569
  • 6
  • 41
  • 45
3
votes
1 answer

ASP.NET Core ViewComponents in different assembly can not be found

I'm trying to load a ViewComponent from a different assembly but in the main project I'm getting the error below InvalidOperationException: A view component named 'Pro.ItemViewComponent' could not be found. A view component must be a public…
2
votes
1 answer

Rails 7, tailwind and view components, classes added to component not compiled / updated

I'm working on a Rails 7 project where I use ViewComponents and Tailwindcss. I'm having some problem getting changes in component's .html.erb files to update properly. When I run ./bin/dev and make css-changes or additions inside…
Anders
  • 2,903
  • 7
  • 58
  • 114
2
votes
1 answer

Modify each block entry to call method on block argument

In one of my views, I rendered a table with a helper method, so the view (haml) looked like this: = table do - action "Add" - column :id - column :name After I changed the helper and used the ViewComponent lib instead, I need to call it the…
andi2.2
  • 86
  • 1
  • 11
2
votes
1 answer

Custom stimulus reflex class

I am working on an experimental project in Rails 6. The purpose of this project for me is to learn new methodologies & play with new("ish") technologies. In short, I am playing around with the Trailblazer infrastructure, stimulus_reflex &…
HermannHH
  • 1,732
  • 1
  • 27
  • 57
1
vote
1 answer

how is the rails way include all user custom helper files in view component

class ApplicationViewComponent < ViewComponent::Base include ApplicationHelper end class FooComponent < ApplicationViewComponent end How can I include not only ApplicationHelper but also user created all helper files in view component?
1
vote
1 answer

How to arrange dynamically passed objects in multiple rows with rails view_component?

I apologize in advance if you think that the title doesn't seem to be appropriate enough to demonstrate the issue precisely. I'm using tailwindcss for rails application. I passed data to view_component with the help of an array containing multiple…
1
vote
2 answers

How to use view_component inside stimulus controller

Hi I am beginner in ROR and working on very simple project using view_components and stimulus js. I have InputCommentComponent view_component which I wanted to append as a child node in div by stimulus controller on click of Some button. But my…
1
vote
1 answer

Passing form data from View Component to Controller in .NET Core MVC

I have a Component View and I try to update data from a form in it, I call the controller but in the controller I receive null : public class CustomerPropertyViewComponent: ViewComponent { private MyDBContext context; public…
1
vote
1 answer

How can I reuse a contact form in a ViewComponent?

I want to use same contact form on multiple pages in my project. I tried it on a sample project named FormInViewComponent as below: Controllers > TestController.cs using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using…
1
vote
3 answers

ViewComponent returns but model is null in view when using route value

I'm still new to Razor pages and view components, but have been around the block a few times with ASP.NET. I'm not sure why my view component doesn't have its model populated. One thing I noticed I had done incorrectly is putting a route parameter…
0
votes
0 answers

Multiple View Components in a hybrid Controller

Is it possible to have more than one view component in an asp.net core Hybrid controller, like child actions in .Net framework MVC? and if yes what naming can they have?
mz1378
  • 1,957
  • 4
  • 20
  • 40
1
2 3