I am trying to create a href to link user(provider) name with user(provider) account view.
I am far from expert in this - tried to copy a part of script from other place in the code where it refers to user(provider) account.
The place where I am trying to add link is:
= render partial: 'services/partials/messages/original_message', locals: { header: t('html.text.consultation_with.for_provider', name: #provider_user.name, type: t("element_names.#{#service.service_type}")),...
and the the part of script which was used to refer to user(provider) account looks like this:
[href="#{provider_path(provider)}" id="provider-#{provider.id}"]
So I tried combining those two:
= render partial: 'services/partials/messages/original_message', locals: { header: t('html.text.consultation_with.for_provider', name: [href="#{provider_path(provider)}" id="provider-#{provider.id}"], type: t("element_names.#{#service.service_type}")),...
And was not surprised that it did not worked..
You can't mix up slim element syntax (the one with square brackets, used by slim itself to create attributes of an element) with ruby code (the arguments to render, it's just a plain ruby method call!)
Maybe this would work for you, or some adaptation:
= render partial: 'services/partials/messages/original_message',
locals: {
header: t('html.text.consultation_with.for_provider',
name: #provider_user.name,
provider_link_href: provider_path(provider),
provider_link_id: "provider-#{provider.id}",
type: t("element_names.#{#service.service_type}")),
...
}
And then in the partial, use them like
a[href=provider_link_href id=provider_link_id]
Text of the link
Related
I have a string with html tags:
html = '</span class="repository-content"> ... </span>'
I need to allow a only specific name for the css class. I use gem sanitize.
This code works well and allows any name for the css class:
Sanitize.fragment(
html,
elements: ['span'],
attributes: { 'span' => ['class'] }
)
But need to allow only the class repository-content. Any other class name must not pass.
How can this be done? any proposal
If instead of inputting html, you input the ... part and build the span like this:
content_tag(:span, ..., class: "repository-content")
then you can write ruby to handle the logic of what to do if the class is not "repository-content".
You may have to sanitize the ..., but you probably won't have to sanitize the output of content_tag.
Okay, I've been having this problem for quite a while now and I can't figure it out. I have a bare-bones app with one controller called 'home' and one action called 'index'. I am using the default layout 'application.html.erb', and in that layout I am using the following:
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
my application.css file contains the following code below the manifest portion:
body {
background-color: blue;
}
and my index file only contains the following snippet:
<p>This is my content!</p>
When I try to access my page, I get the following error:
JSON::ParserError in Home#index
Does anyone know what is happening?
Thanks in advance!
EDIT
class HomeController < ApplicationController
def index
end
end
Within a sinatra framework, I'm trying to yield a template, dashboard.haml, within a layout template: layout.haml. But when the page loads, a stringified version of the html appears, instead of the HTML itself. So it's clearly fetching the correct template, but I wonder why the html is being rendered as a string??
Here are the relevant code:
server.rb
get '/:developer' do
#workflow_audits = Auditor.new(params['developer']).workflow_audits
haml :dashboard, :layout => :layout
end
views/layout.haml
%html
%head
%title Workflow Stuff
%link{ :rel => :stylesheet, :type => "text/scss", :href => "/stylesheets/dashboard.scss"}
%script{ :src => "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js" }
%body
%form{action: '/', method: 'post'}
%label{for: 'developer'}Select a developer:
%input{type: 'text', name: 'developer'}
%input{type: 'submit', value: 'submit'}
= yield
views/dashboard.haml
%ul.issue-list
- #workflow_audits.each do |audit|
%li.issue
.issue-container.row
You have an indentation issue in dashboard.haml. I removed the 3 spaces and tabs in your post and put two spaces everywhere, all errors went away and was able to get it working.
%ul.issue-list
- #workflow_audits.each do |audit|
%li.issue
.issue-container.row
On each text_area on my site, I have a select_box for selecting the language. It often uses certain default languages, but sometimes checks for custom options. I initially had the array setup in the controller:
#language_array = [ ["english", 1], ["french", 2], ["spanish", 3] ]
#language_array = get_custom_array if custom_language?
And it would then be accessed by the view:
<%= select_tag(:language, options_for_select(language_array, default_language) )%>
This worked fine, and the text_area would display the language and pass on the number. However, I would now like to add multiple text_areas to each page, so I moved the code into a helper, and access the helper from every text_area in the view:
language_array = get_language_array(thing.id)
<%= select_tag(:language, options_for_select(language_array, default_language) )%>
However, now the text_area comes out messed up, and displays the array instead of just the language:
["english", 1]
How can I fix it (without changing the currently stored arrays)? I also want variables from the helper to be available to javascript on the page. Is there a better way to deal with multiple "things" than to move everything from the controller to the helpers?
You could have them inside the model as a hash like this
user.rb
def User
def self.language
{
'English' => '1',
'French' => '2',
....
}
end
end
and in the controller obtain the hash into a variable and it will be accessible in both the html.erb and the js.erb
users_controller.rb
#language = User.language
Then while building the form you can do it as
<%= talent_field.select(:language, #language, {}, {:class => 'language-select'} %>
Basically I am trying to get this output in Rails and Slim:
my<strong>name</strong>
This is what I have so far:
= link_to 'my<strong>name</strong>', controller: :pages, action: :home
Obviously it outputs:
my<strong>name</strong> on the page instead of interpreting the strong tags. Any thoughts?
You need to Rails that the string is safe :
= link_to 'my<strong...>'.html_safe